Bug 1282795 - Silence warnings when MOZ_ALWAYS_{TRUE,FALSE} are passed expressions with embedded side effects, that would ordinarily trigger side effects but don't inside certain unevaluated contexts within MOZ_ASSERT, which then triggers compiler warnings with new-enough clang. You are not expected to understand this. r=froydnj
authorJeff Walden <jwalden@mit.edu>
Tue, 28 Jun 2016 17:12:14 +0100
changeset 345181 cd248c790c8c9d3ca3eba319858244259d7cba79
parent 345180 ddd5a4c1edc8774f7a0179856ecfec36164a4795
child 345182 6fef5909e6174def4b8d545dfd239a491055fa90
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1282795
milestone50.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 1282795 - Silence warnings when MOZ_ALWAYS_{TRUE,FALSE} are passed expressions with embedded side effects, that would ordinarily trigger side effects but don't inside certain unevaluated contexts within MOZ_ASSERT, which then triggers compiler warnings with new-enough clang. You are not expected to understand this. r=froydnj
mfbt/Assertions.h
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -537,29 +537,43 @@ struct AssertionConditionType
 
 /*
  * MOZ_ALWAYS_TRUE(expr) and MOZ_ALWAYS_FALSE(expr) always evaluate the provided
  * expression, in debug builds and in release builds both.  Then, in debug
  * builds only, the value of the expression is asserted either true or false
  * using MOZ_ASSERT.
  */
 #ifdef DEBUG
-#  define MOZ_ALWAYS_TRUE(expr)      MOZ_ASSERT((expr))
-#  define MOZ_ALWAYS_FALSE(expr)     MOZ_ASSERT(!(expr))
+#  define MOZ_ALWAYS_TRUE(expr) \
+     do { \
+       if ((expr)) { \
+         /* Do nothing. */ \
+       } else { \
+         MOZ_ASSERT(false, #expr); \
+       } \
+     } while (0)
+#  define MOZ_ALWAYS_FALSE(expr) \
+     do { \
+       if ((expr)) { \
+         MOZ_ASSERT(false, #expr); \
+       } else { \
+         /* Do nothing. */ \
+       } \
+     } while (0)
 #else
 #  define MOZ_ALWAYS_TRUE(expr) \
-  do { \
-    if ( ( expr ) ) { \
-      /* Silence MOZ_MUST_USE. */ \
-    } \
-  } while (0)
+     do { \
+       if ((expr)) { \
+          /* Silence MOZ_MUST_USE. */ \
+       } \
+     } while (0)
 #  define MOZ_ALWAYS_FALSE(expr) \
-  do { \
-    if ( ( expr ) ) { \
-      /* Silence MOZ_MUST_USE. */ \
-    } \
-  } while (0)
+     do { \
+       if ((expr)) { \
+         /* Silence MOZ_MUST_USE. */ \
+       } \
+     } while (0)
 #endif
 
 #undef MOZ_DUMP_ASSERTION_STACK
 #undef MOZ_CRASH_CRASHREPORT
 
 #endif /* mozilla_Assertions_h */