diff options
author | Adam Borowski <kilobyte@angband.pl> | 2012-06-03 00:52:45 +0200 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2012-06-03 00:52:45 +0200 |
commit | d26281446914221c3de786faf3131e0ef106f9e6 (patch) | |
tree | 27c8ec7fb3d5c4209501aeec68deefe1db72ca47 /crawl-ref/source/debug.h | |
parent | d6b31b0f7391bf8536130dce0b371469b2938bdf (diff) | |
download | crawl-ref-d26281446914221c3de786faf3131e0ef106f9e6.tar.gz crawl-ref-d26281446914221c3de786faf3131e0ef106f9e6.zip |
Make COMPILE_CHECK work both with --std=c++11 and on gcc-4.8.
I could just use the sizeof() trick everywhere, but:
* the old way produced a better message on gcc before 4.8 (it included the
words "compile_check")
* if C++11 has explicit support for this (static_assert()), we can use it
when building in that mode (not the default for Crawl)
Diffstat (limited to 'crawl-ref/source/debug.h')
-rw-r--r-- | crawl-ref/source/debug.h | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/crawl-ref/source/debug.h b/crawl-ref/source/debug.h index 7391d13b0b..e8182ca870 100644 --- a/crawl-ref/source/debug.h +++ b/crawl-ref/source/debug.h @@ -27,9 +27,22 @@ #ifndef _lint -#define COMPILE_CHECK(expr) typedef char compile_check_ ## __LINE__[(expr) ? 1 : -1] +# if defined(__cplusplus) && __cplusplus >= 201103 +// We'd need to enable C++11 mode for nice messages. +# define COMPILE_CHECK(expr) static_assert((expr), #expr) +# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112 +// ... or C11 mode (with a different keyword). +# define COMPILE_CHECK(expr) _Static_assert((expr), #expr) +# elif defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 8) +// Otherwise, use a hack. +# define COMPILE_CHECK(expr) ((void)sizeof(char[1 - 2*!(expr)])) +# else +// Or one with a slightly better message, except that GCC-4.8 notices it's +// nonsense and spams warnings on non-failures. +# define COMPILE_CHECK(expr) typedef char compile_check_ ## __LINE__[(expr) ? 1 : -1] +# endif #else -#define COMPILE_CHECK(expr) +# define COMPILE_CHECK(expr) #endif #if defined(DEBUG) && !defined(ASSERTS) |