From 3ce38e536eecc3c34a05a048adb4ff803b0a6b62 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sat, 24 Jan 2015 17:29:19 +0000 Subject: [PATCH] Update cassert to use C++11 static_assert. This gives clearer error messages, and simplifies the code. This was SVN commit r16216. --- source/lib/alignment.h | 2 +- source/lib/bits.h | 2 +- source/lib/code_annotation.h | 32 ++------------------------------ 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/source/lib/alignment.h b/source/lib/alignment.h index a294a0fea4..1135f9c066 100644 --- a/source/lib/alignment.h +++ b/source/lib/alignment.h @@ -13,7 +13,7 @@ inline bool IsAligned(T t, uintptr_t multiple) template inline size_t Align(size_t n) { - cassert_dependent(multiple != 0 && ((multiple & (multiple-1)) == 0)); // is power of 2 + cassert(multiple != 0 && ((multiple & (multiple-1)) == 0)); // is power of 2 return (n + multiple-1) & ~(multiple-1); } diff --git a/source/lib/bits.h b/source/lib/bits.h index 46f3e7b9ef..d70864dbca 100644 --- a/source/lib/bits.h +++ b/source/lib/bits.h @@ -147,7 +147,7 @@ inline size_t SparsePopulationCount(T mask) template static inline size_t PopulationCount(T x) { - cassert_dependent(!std::numeric_limits::is_signed); + cassert(!std::numeric_limits::is_signed); const T mask = T(~T(0)); x -= (x >> 1) & (mask/3); // count 2 bits x = (x & (mask/15*3)) + ((x >> 2) & (mask/15*3)); // count 4 bits diff --git a/source/lib/code_annotation.h b/source/lib/code_annotation.h index f8b4544bd7..19bced1fa1 100644 --- a/source/lib/code_annotation.h +++ b/source/lib/code_annotation.h @@ -161,7 +161,7 @@ switch(x % 2) // generate a symbol containing the line number of the macro invocation. -// used to give a unique name (per file) to types made by cassert. +// used to give a unique name (per file) to types or variables. // we can't prepend __FILE__ to make it globally unique - the filename // may be enclosed in quotes. PASTE3_HIDDEN__ is needed to make sure // __LINE__ is expanded correctly. @@ -174,13 +174,6 @@ switch(x % 2) //----------------------------------------------------------------------------- // cassert -// Silence warnings about unused local typedefs -#if GCC_VERSION >= 408 -# define UNUSED_ATTRIBUTE __attribute__((unused)) -#else -# define UNUSED_ATTRIBUTE -#endif - /** * Compile-time assertion. Causes a compile error if the expression * evaluates to zero/false. @@ -190,28 +183,7 @@ switch(x % 2) * * @param expr Expression that is expected to evaluate to non-zero at compile-time. **/ -#define cassert(expr) typedef static_assert_<(expr)>::type UID__ UNUSED_ATTRIBUTE -template struct static_assert_; -template<> struct static_assert_ -{ - typedef int type; -}; - -/** - * @copydoc cassert(expr) - * - * This version must be used if expr uses a dependent type (e.g. depends on - * a template parameter). - **/ -#define cassert_dependent(expr) typedef typename static_assert_<(expr)>::type UID__ UNUSED_ATTRIBUTE - -/** - * @copydoc cassert(expr) - * - * This version has a less helpful error message, but redefinition doesn't - * trigger warnings. - **/ -#define cassert2(expr) extern char CASSERT_FAILURE[1][(expr)] +#define cassert(expr) static_assert((expr), #expr) /**