[Openmp-commits] [openmp] r292350 - Use C++11 static_assert() for build asserts.

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Tue Jan 17 23:49:30 PST 2017


Author: jlpeyton
Date: Wed Jan 18 01:49:30 2017
New Revision: 292350

URL: http://llvm.org/viewvc/llvm-project?rev=292350&view=rev
Log:
Use C++11 static_assert() for build asserts.

Modified:
    openmp/trunk/runtime/src/kmp_debug.h

Modified: openmp/trunk/runtime/src/kmp_debug.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_debug.h?rev=292350&r1=292349&r2=292350&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_debug.h (original)
+++ openmp/trunk/runtime/src/kmp_debug.h Wed Jan 18 01:49:30 2017
@@ -26,27 +26,8 @@
 // Build-time assertion.
 // -------------------------------------------------------------------------------------------------
 
-/*
-    Build-time assertion can do compile-time checking of data structure sizes, etc. This works by
-    declaring a negative-length array if the conditional expression evaluates to false.  In that
-    case, the compiler issues a syntax error and stops the compilation. If the expression is
-    true, we get an extraneous static single character array in the scope of the macro.
-
-    Usage:
-
-        KMP_BUILD_ASSERT( sizeof( some_t ) <= 32 );
-        KMP_BUILD_ASSERT( offsetof( some_t, field ) % 8 == 0 );
-
-    Do not use _KMP_BUILD_ASSERT and __KMP_BUILD_ASSERT directly, it is working guts.
-*/
-
-#define __KMP_BUILD_ASSERT( expr, suffix )  typedef char __kmp_build_check_##suffix[ (expr) ? 1 : -1 ]
-#define _KMP_BUILD_ASSERT( expr, suffix )   __KMP_BUILD_ASSERT( (expr), suffix )
-#ifdef KMP_USE_ASSERT
-    #define KMP_BUILD_ASSERT( expr )            _KMP_BUILD_ASSERT( (expr), __LINE__ )
-#else
-    #define KMP_BUILD_ASSERT( expr )            /* nothing to do */
-#endif
+// New C++11 style build assert
+#define KMP_BUILD_ASSERT( expr )            static_assert(expr, "Build condition error")
 
 // -------------------------------------------------------------------------------------------------
 // Run-time assertions.




More information about the Openmp-commits mailing list