Bug 895322 - Part 5: Stop #defining MOZ_STATIC_ASSERT in C++ code; r=Waldo
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 18 Jul 2013 14:39:20 -0400
changeset 140599 b5506e604ae47f5b764450bfef41f5245fbd9529
parent 140598 851bab4e2e3a68c5f7b7f3b17cb7d1acd7a893d5
child 140600 dd1908156c2f3abbb60b0e1d97cc2a3356725a93
push id25033
push userryanvm@gmail.com
push dateWed, 31 Jul 2013 01:29:46 +0000
treeherdermozilla-central@c2b375f3a909 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs895322
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 895322 - Part 5: Stop #defining MOZ_STATIC_ASSERT in C++ code; r=Waldo
mfbt/Assertions.h
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -35,54 +35,34 @@
 #else
 #  include <signal.h>
 #endif
 #ifdef ANDROID
 #  include <android/log.h>
 #endif
 
 /*
- * MOZ_STATIC_ASSERT may be used to assert a condition *at compile time*.  This
- * can be useful when you make certain assumptions about what must hold for
+ * MOZ_STATIC_ASSERT may be used to assert a condition *at compile time* in C.
+ * In C++11, static_assert is provided by the compiler to the same effect.
+ * This can be useful when you make certain assumptions about what must hold for
  * optimal, or even correct, behavior.  For example, you might assert that the
  * size of a struct is a multiple of the target architecture's word size:
  *
  *   struct S { ... };
+ *   // C
  *   MOZ_STATIC_ASSERT(sizeof(S) % sizeof(size_t) == 0,
  *                     "S should be a multiple of word size for efficiency");
+ *   // C++11
+ *   static_assert(sizeof(S) % sizeof(size_t) == 0,
+ *                 "S should be a multiple of word size for efficiency");
  *
  * This macro can be used in any location where both an extern declaration and a
  * typedef could be used.
- *
- * Be aware of the gcc 4.2 concerns noted further down when writing patches that
- * use this macro, particularly if a patch only bounces on OS X.
  */
-#ifdef __cplusplus
-#  if defined(__clang__)
-#    ifndef __has_extension
-#      define __has_extension __has_feature /* compatibility, for older versions of clang */
-#    endif
-#    if __has_extension(cxx_static_assert)
-#      define MOZ_STATIC_ASSERT(cond, reason)    static_assert((cond), reason)
-#    endif
-#  elif defined(__GNUC__)
-#    if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L)
-#      define MOZ_STATIC_ASSERT(cond, reason)    static_assert((cond), reason)
-#    endif
-#  elif defined(_MSC_VER)
-#    if _MSC_VER >= 1600 /* MSVC 10 */
-#      define MOZ_STATIC_ASSERT(cond, reason)    static_assert((cond), reason)
-#    endif
-#  elif defined(__HP_aCC)
-#    if __HP_aCC >= 62500 && defined(_HP_CXX0x_SOURCE)
-#      define MOZ_STATIC_ASSERT(cond, reason)    static_assert((cond), reason)
-#    endif
-#  endif
-#endif
-#ifndef MOZ_STATIC_ASSERT
+#ifndef __cplusplus
    /*
     * Some of the definitions below create an otherwise-unused typedef.  This
     * triggers compiler warnings with some versions of gcc, so mark the typedefs
     * as permissibly-unused to disable the warnings.
     */
 #  if defined(__GNUC__)
 #    define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__((unused))
 #  else
@@ -120,19 +100,21 @@
       * code.
       */
 #    define MOZ_STATIC_ASSERT(cond, reason) \
        typedef int MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __COUNTER__)[(cond) ? 1 : -1] MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE
 #  else
 #    define MOZ_STATIC_ASSERT(cond, reason) \
        extern void MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __LINE__)(int arg[(cond) ? 1 : -1]) MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE
 #  endif
-#endif
 
 #define MOZ_STATIC_ASSERT_IF(cond, expr, reason)  MOZ_STATIC_ASSERT(!(cond) || (expr), reason)
+#else
+#define MOZ_STATIC_ASSERT_IF(cond, expr, reason)  static_assert(!(cond) || (expr), reason)
+#endif
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /*
  * Prints |s| as an assertion failure (using file and ln as the location of the
  * assertion) to the standard debug-output channel.