Bug 851237 - Mark the static-assert typedef with an unused attribute so it doesn't trigger compiler warnings. r=dholbert
authorJeff Walden <jwalden@mit.edu>
Thu, 21 Mar 2013 18:26:06 -0700
changeset 125889 9455756963a42b281b40cd00a0c6834b92553582
parent 125888 d550a01e0ab235aee04fcc84db312c7b447e3196
child 125890 af13119deb4711ae301d1716a48da9b761b0800c
push id24464
push useremorley@mozilla.com
push dateFri, 22 Mar 2013 14:00:12 +0000
treeherdermozilla-central@3825fdbcec62 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs851237
milestone22.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 851237 - Mark the static-assert typedef with an unused attribute so it doesn't trigger compiler warnings. r=dholbert
mfbt/Assertions.h
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -71,16 +71,26 @@
 #    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
+   /*
+    * 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
+#    define MOZ_STATIC_ASSERT_UNUSED_ATTRIBUTE /* nothing */
+#  endif
 #  define MOZ_STATIC_ASSERT_GLUE1(x, y)          x##y
 #  define MOZ_STATIC_ASSERT_GLUE(x, y)           MOZ_STATIC_ASSERT_GLUE1(x, y)
 #  if defined(__SUNPRO_CC)
      /*
       * The Sun Studio C++ compiler is buggy when declaring, inside a function,
       * another extern'd function with an array argument whose length contains a
       * sizeof, triggering the error message "sizeof expression not accepted as
       * size of array parameter".  This bug (6688515, not public yet) would hit
@@ -103,20 +113,20 @@
       * we include the line number in the function name to do the best we can to
       * avoid conflicts.  These should be rare: a conflict would require use of
       * MOZ_STATIC_ASSERT on the same line in separate files in the same
       * translation unit, *and* the uses would have to be in code with
       * different linkage, *and* the first observed use must be in C++-linkage
       * code.
       */
 #    define MOZ_STATIC_ASSERT(cond, reason) \
-       typedef int MOZ_STATIC_ASSERT_GLUE(moz_static_assert, __COUNTER__)[(cond) ? 1 : -1]
+       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])
+       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)
 
 #ifdef __cplusplus
 extern "C" {
 #endif