Commit bc56e509 authored by Kenton Varda's avatar Kenton Varda

Don't ever auto-define NDEBUG. Just decide KJ_DEBUG based on optimization mode…

Don't ever auto-define NDEBUG.  Just decide KJ_DEBUG based on optimization mode if neither DEBUG nor NDEBUG is defined.
parent 43e8ba1a
......@@ -98,16 +98,18 @@ typedef unsigned char byte;
#endif
#endif
#if __OPTIMIZE__ && !defined(NDEBUG) && !defined(DEBUG) && !defined(KJ_DEBUG)
#warning "You've enabled optimization but not NDEBUG. Usually optimized builds should #define \
NDEBUG to disable debug asserts, so I am #defining it for you. If you actually want debug asserts, \
please #define DEBUG or KJ_DEBUG. To make this warning go away, #define NDEBUG yourself, e.g. with \
the compiler flag -DNDEBUG."
#define NDEBUG 1
#endif
#if !defined(NDEBUG) && !defined(KJ_DEBUG)
#if !defined(KJ_DEBUG) && !defined(KJ_NDEBUG)
// Heuristically decide whether to enable debug mode. If DEBUG or NDEBUG is defined, use that.
// Otherwise, fall back to checking whether optimization is enabled.
#if defined(DEBUG)
#define KJ_DEBUG
#elif defined(NDEBUG)
#define KJ_NDEBUG
#elif __OPTIMIZE__
#define KJ_NDEBUG
#else
#define KJ_DEBUG
#endif
#endif
#define KJ_DISALLOW_COPY(classname) \
......
......@@ -101,7 +101,10 @@
// `FAIL_RECOVERABLE_SYSCALL` take a string and an OS error number as the first two parameters.
// The string should be the name of the failed system call.
// * For every macro `FOO` above, there is a `DFOO` version (or `RECOVERABLE_DFOO`) which is only
// executed in debug mode. When `NDEBUG` is defined, these macros expand to nothing.
// executed in debug mode, i.e. when KJ_DEBUG is defined. KJ_DEBUG is defined automatically
// by common.h when compiling without optimization (unless NDEBUG is defined), but you can also
// define it explicitly (e.g. -DKJ_DEBUG). Generally, production builds should NOT use KJ_DEBUG
// as it may enable expensive checks that are unlikely to fail.
#ifndef KJ_DEBUG_H_
#define KJ_DEBUG_H_
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment