netheril96 / cpp-btree

Automatically exported from code.google.com/p/cpp-btree
Apache License 2.0
2 stars 0 forks source link

NDEBUG defined in btree.h #20

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Compile and run a program like:

#undef NDEBUG

#include "btree_set.h"
#include <cassert>

int main (void) {
    assert(false);
}

What is the expected output? What do you see instead?

The assertion should fail. Instead the assertion is skipped since btree.h has 
defined NDEBUG to 1. Reversing the order of includes would paper over the issue.

Original issue reported on code.google.com by jsn...@gmail.com on 3 May 2013 at 10:36

GoogleCodeExporter commented 9 years ago
Specifically, NDEBUG is one of those very old-school macros for which being 
defined to ANY value, including 0, is treated as true. (Any argument you could 
make that this is stupid, that undefined should mean "available for other code 
to set the default" as opposed to false, would be wasted on me because I agree, 
but it is what it is.) Defining NDEBUG to 0 means to turn off debugging code, 
same as defining it to 1. So, the fix is:

< #define NDEBUG 1
---
> //#define NDEBUG 1
693c693
<     if (!NDEBUG) {
---
> #if !NDEBUG
695c695
<     }
---
> #endif
701c701
<     if (!NDEBUG) {
---
> #if !NDEBUG
703c703
<     }
---
> #endif

Original comment by scott.r...@gmail.com on 26 Jul 2013 at 9:49