COMMON: Use C++11 static_assert when available
This improves the output of static assertions in all compilers, and prevents problems in MSVC 2015 where the mechanism for triggering a compilation error in C++98 mode may cause errors when that compiler builds in release mode. Fixes Trac#10154.
This commit is contained in:
parent
600fe749c5
commit
2de83e0937
1 changed files with 16 additions and 2 deletions
|
@ -154,6 +154,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef STATIC_ASSERT
|
#ifndef STATIC_ASSERT
|
||||||
|
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER > 1600)
|
||||||
/**
|
/**
|
||||||
* Generates a compile-time assertion.
|
* Generates a compile-time assertion.
|
||||||
*
|
*
|
||||||
|
@ -162,8 +163,21 @@
|
||||||
* time if the expression evaluates to false.
|
* time if the expression evaluates to false.
|
||||||
*/
|
*/
|
||||||
#define STATIC_ASSERT(expression, message) \
|
#define STATIC_ASSERT(expression, message) \
|
||||||
extern int STATIC_ASSERT_##message[(expression) ? 1 : -1]; \
|
static_assert((expression), #message)
|
||||||
(void)(STATIC_ASSERT_##message);
|
#else
|
||||||
|
/**
|
||||||
|
* Generates a compile-time assertion.
|
||||||
|
*
|
||||||
|
* @param expression An expression that can be evaluated at compile time.
|
||||||
|
* @param message An underscore-delimited message to be presented at compile
|
||||||
|
* time if the expression evaluates to false.
|
||||||
|
*/
|
||||||
|
#define STATIC_ASSERT(expression, message) \
|
||||||
|
do { \
|
||||||
|
extern int STATIC_ASSERT_##message[(expression) ? 1 : -1]; \
|
||||||
|
(void)(STATIC_ASSERT_##message); \
|
||||||
|
} while (false)
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// The following math constants are usually defined by the system math.h header, but
|
// The following math constants are usually defined by the system math.h header, but
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue