Bug 1370794 - Use bool instead of integer being casted to bool r?froydnj draft
authorSylvestre Ledru <sledru@mozilla.com>
Wed, 07 Feb 2018 15:15:28 +0100
changeset 752061 109a3298f9d3e116359b34a436fc167cba74c929
parent 752060 0da6edf23a3967476177727288290bd8e5fb653a
child 752062 72066778b21f481f2490c5aea33ee9cda826d44b
push id98157
push userbmo:sledru@mozilla.com
push dateWed, 07 Feb 2018 14:27:36 +0000
reviewersfroydnj
bugs1370794
milestone60.0a1
Bug 1370794 - Use bool instead of integer being casted to bool r?froydnj MozReview-Commit-ID: lUVFeU0Y0p
mfbt/Assertions.h
xpcom/base/nsDebug.h
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -36,17 +36,17 @@ MOZ_END_EXTERN_C
 #if !defined(DEBUG) && (defined(MOZ_HAS_MOZGLUE) || defined(MOZILLA_INTERNAL_API))
 static inline void
 AnnotateMozCrashReason(const char* reason)
 {
   gMozCrashReason = reason;
 }
 #  define MOZ_CRASH_ANNOTATE(...) AnnotateMozCrashReason(__VA_ARGS__)
 #else
-#  define MOZ_CRASH_ANNOTATE(...) do { /* nothing */ } while (0)
+#  define MOZ_CRASH_ANNOTATE(...) do { /* nothing */ } while (false)
 #endif
 
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #ifdef _MSC_VER
    /*
     * TerminateProcess and GetCurrentProcess are defined in <winbase.h>, which
@@ -214,30 +214,30 @@ MOZ_NoReturn(int aLine)
   *((volatile int*) NULL) = aLine;
   TerminateProcess(GetCurrentProcess(), 3);
 }
 
 #  define MOZ_REALLY_CRASH(line) \
      do { \
        __debugbreak(); \
        MOZ_NoReturn(line); \
-     } while (0)
+     } while (false)
 #else
 #  ifdef __cplusplus
 #    define MOZ_REALLY_CRASH(line) \
        do { \
          *((volatile int*) NULL) = line; \
          ::abort(); \
-       } while (0)
+       } while (false)
 #  else
 #    define MOZ_REALLY_CRASH(line) \
        do { \
          *((volatile int*) NULL) = line; \
          abort(); \
-       } while (0)
+       } while (false)
 #  endif
 #endif
 
 /*
  * MOZ_CRASH([explanation-string]) crashes the program, plain and simple, in a
  * Breakpad-compatible way, in both debug and release builds.
  *
  * MOZ_CRASH is a good solution for "handling" failure cases when you're
@@ -257,24 +257,24 @@ MOZ_NoReturn(int aLine)
  * builds, and it's hard to print to stderr safely when memory might have been
  * corrupted.
  */
 #ifndef DEBUG
 #  define MOZ_CRASH(...) \
      do { \
        MOZ_CRASH_ANNOTATE("MOZ_CRASH(" __VA_ARGS__ ")"); \
        MOZ_REALLY_CRASH(__LINE__); \
-     } while (0)
+     } while (false)
 #else
 #  define MOZ_CRASH(...) \
      do { \
        MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \
        MOZ_CRASH_ANNOTATE("MOZ_CRASH(" __VA_ARGS__ ")"); \
        MOZ_REALLY_CRASH(__LINE__); \
-     } while (0)
+     } while (false)
 #endif
 
 /*
  * MOZ_CRASH_UNSAFE_OOL(explanation-string) can be used if the explanation
  * string cannot be a string literal (but no other processing needs to be done
  * on it). A regular MOZ_CRASH() is preferred wherever possible, as passing
  * arbitrary strings from a potentially compromised process is not without risk.
  * If the string being passed is the result of a printf-style function,
@@ -328,17 +328,17 @@ MOZ_CrashPrintf(const char* aFilename, i
        "Did you forget arguments to MOZ_CRASH_UNSAFE_PRINTF? " \
        "Or maybe you want MOZ_CRASH instead?"); \
      static_assert( \
        MOZ_ARG_COUNT(__VA_ARGS__) <= sPrintfMaxArgs, \
        "Only up to 4 additional arguments are allowed!"); \
      static_assert(sizeof(format) <= sPrintfCrashReasonSize, \
        "The supplied format string is too long!"); \
      MOZ_CALL_CRASH_PRINTF("" format, __VA_ARGS__); \
-   } while (0)
+   } while (false)
 
 MOZ_END_EXTERN_C
 
 /*
  * MOZ_ASSERT(expr [, explanation-string]) asserts that |expr| must be truthy in
  * debug builds.  If it is, execution continues.  Otherwise, an error message
  * including the expression and the explanation-string (if provided) is printed,
  * an attempt is made to invoke any existing debugger, and execution halts.
@@ -418,50 +418,50 @@ struct AssertionConditionType
                    "invalid assertion condition")
 #else
 #  define MOZ_VALIDATE_ASSERT_CONDITION_TYPE(x)
 #endif
 
 #if defined(DEBUG) || defined(MOZ_ASAN)
 #  define MOZ_REPORT_ASSERTION_FAILURE(...) MOZ_ReportAssertionFailure(__VA_ARGS__)
 #else
-#  define MOZ_REPORT_ASSERTION_FAILURE(...) do { /* nothing */ } while (0)
+#  define MOZ_REPORT_ASSERTION_FAILURE(...) do { /* nothing */ } while (false)
 #endif
 
 /* First the single-argument form. */
 #define MOZ_ASSERT_HELPER1(expr) \
   do { \
     MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \
     if (MOZ_UNLIKELY(!MOZ_CHECK_ASSERT_ASSIGNMENT(expr))) { \
       MOZ_REPORT_ASSERTION_FAILURE(#expr, __FILE__, __LINE__); \
       MOZ_CRASH_ANNOTATE("MOZ_RELEASE_ASSERT(" #expr ")"); \
       MOZ_REALLY_CRASH(__LINE__); \
     } \
-  } while (0)
+  } while (false)
 /* Now the two-argument form. */
 #define MOZ_ASSERT_HELPER2(expr, explain) \
   do { \
     MOZ_VALIDATE_ASSERT_CONDITION_TYPE(expr); \
     if (MOZ_UNLIKELY(!MOZ_CHECK_ASSERT_ASSIGNMENT(expr))) { \
       MOZ_REPORT_ASSERTION_FAILURE(#expr " (" explain ")", __FILE__, __LINE__); \
       MOZ_CRASH_ANNOTATE("MOZ_RELEASE_ASSERT(" #expr ") (" explain ")"); \
       MOZ_REALLY_CRASH(__LINE__); \
     } \
-  } while (0)
+  } while (false)
 
 #define MOZ_RELEASE_ASSERT_GLUE(a, b) a b
 #define MOZ_RELEASE_ASSERT(...) \
   MOZ_RELEASE_ASSERT_GLUE( \
     MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \
     (__VA_ARGS__))
 
 #ifdef DEBUG
 #  define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__)
 #else
-#  define MOZ_ASSERT(...) do { } while (0)
+#  define MOZ_ASSERT(...) do { } while (false)
 #endif /* DEBUG */
 
 #if defined(NIGHTLY_BUILD) || defined(MOZ_DEV_EDITION)
 #  define MOZ_DIAGNOSTIC_ASSERT MOZ_RELEASE_ASSERT
 #  define MOZ_DIAGNOSTIC_ASSERT_ENABLED 1
 #else
 #  define MOZ_DIAGNOSTIC_ASSERT MOZ_ASSERT
 #  ifdef DEBUG
@@ -479,19 +479,19 @@ struct AssertionConditionType
  * designed to catch bugs during debugging, not "in the field".
  */
 #ifdef DEBUG
 #  define MOZ_ASSERT_IF(cond, expr) \
      do { \
        if (cond) { \
          MOZ_ASSERT(expr); \
        } \
-     } while (0)
+     } while (false)
 #else
-#  define MOZ_ASSERT_IF(cond, expr)  do { } while (0)
+#  define MOZ_ASSERT_IF(cond, expr)  do { } while (false)
 #endif
 
 /*
  * MOZ_ASSUME_UNREACHABLE_MARKER() expands to an expression which states that
  * it is undefined behavior for execution to reach this point.  No guarantees
  * are made about what will happen if this is reached at runtime.  Most code
  * should use MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE because it has extra
  * asserts.
@@ -555,26 +555,26 @@ struct AssertionConditionType
  */
 #define MOZ_ASSERT_UNREACHABLE(reason) \
    MOZ_ASSERT(false, "MOZ_ASSERT_UNREACHABLE: " reason)
 
 #define MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE(reason) \
    do { \
      MOZ_ASSERT_UNREACHABLE(reason); \
      MOZ_ASSUME_UNREACHABLE_MARKER(); \
-   } while (0)
+   } while (false)
 
 /**
  * MOZ_FALLTHROUGH_ASSERT is an annotation to suppress compiler warnings about
  * switch cases that MOZ_ASSERT(false) (or its alias MOZ_ASSERT_UNREACHABLE) in
  * debug builds, but intentionally fall through in release builds to handle
  * unexpected values.
  *
  * Why do we need MOZ_FALLTHROUGH_ASSERT in addition to MOZ_FALLTHROUGH? In
- * release builds, the MOZ_ASSERT(false) will expand to `do { } while (0)`,
+ * release builds, the MOZ_ASSERT(false) will expand to `do { } while (false)`,
  * requiring a MOZ_FALLTHROUGH annotation to suppress a -Wimplicit-fallthrough
  * warning. In debug builds, the MOZ_ASSERT(false) will expand to something like
  * `if (true) { MOZ_CRASH(); }` and the MOZ_FALLTHROUGH annotation will cause
  * a -Wunreachable-code warning. The MOZ_FALLTHROUGH_ASSERT macro breaks this
  * warning stalemate.
  *
  * // Example before MOZ_FALLTHROUGH_ASSERT:
  * switch (foo) {
@@ -610,50 +610,50 @@ struct AssertionConditionType
 #ifdef DEBUG
 #  define MOZ_ALWAYS_TRUE(expr) \
      do { \
        if ((expr)) { \
          /* Do nothing. */ \
        } else { \
          MOZ_ASSERT(false, #expr); \
        } \
-     } while (0)
+     } while (false)
 #  define MOZ_ALWAYS_FALSE(expr) \
      do { \
        if ((expr)) { \
          MOZ_ASSERT(false, #expr); \
        } else { \
          /* Do nothing. */ \
        } \
-     } while (0)
+     } while (false)
 #  define MOZ_ALWAYS_OK(expr)        MOZ_ASSERT((expr).isOk())
 #  define MOZ_ALWAYS_ERR(expr)       MOZ_ASSERT((expr).isErr())
 #else
 #  define MOZ_ALWAYS_TRUE(expr) \
      do { \
        if ((expr)) { \
           /* Silence MOZ_MUST_USE. */ \
        } \
-     } while (0)
+     } while (false)
 #  define MOZ_ALWAYS_FALSE(expr) \
      do { \
        if ((expr)) { \
          /* Silence MOZ_MUST_USE. */ \
        } \
-     } while (0)
+     } while (false)
 #  define MOZ_ALWAYS_OK(expr) \
      do { \
        if ((expr).isOk()) { \
          /* Silence MOZ_MUST_USE. */ \
        } \
-     } while (0)
+     } while (false)
 #  define MOZ_ALWAYS_ERR(expr) \
      do { \
        if ((expr).isErr()) { \
          /* Silence MOZ_MUST_USE. */ \
        } \
-     } while (0)
+     } while (false)
 #endif
 
 #undef MOZ_DUMP_ASSERTION_STACK
 #undef MOZ_CRASH_CRASHREPORT
 
 #endif /* mozilla_Assertions_h */
--- a/xpcom/base/nsDebug.h
+++ b/xpcom/base/nsDebug.h
@@ -74,19 +74,19 @@ inline MOZ_MUST_USE bool NS_warn_if_impl
  * evaluate the message argument.
  */
 #ifdef DEBUG
 #define NS_WARNING_ASSERTION(_expr, _msg)                     \
   do {                                                        \
     if (!(_expr)) {                                           \
       NS_DebugBreak(NS_DEBUG_WARNING, _msg, #_expr, __FILE__, __LINE__); \
     }                                                         \
-  } while(0)
+  } while(false)
 #else
-#define NS_WARNING_ASSERTION(_expr, _msg)  do { /* nothing */ } while(0)
+#define NS_WARNING_ASSERTION(_expr, _msg)  do { /* nothing */ } while(false)
 #endif
 
 /**
  * Test an assertion for truth. If the expression is not true then
  * trigger a program failure.
  *
  * Note that the non-debug version of this macro does <b>not</b>
  * evaluate the message argument.
@@ -181,35 +181,35 @@ inline void MOZ_PretendNoReturn()
 /* Used to make identifiers for assert/assume annotations in a function. */
 #define STATIC_PASTE2(X,Y) X ## Y
 #define STATIC_PASTE1(X,Y) STATIC_PASTE2(X,Y)
 
 #define STATIC_ASSUME(COND)                          \
   do {                                               \
     __attribute__((assume_static(#COND), unused))    \
     int STATIC_PASTE1(assume_static_, __COUNTER__);  \
-  } while(0)
+  } while(false)
 
 #define STATIC_ASSERT_RUNTIME(COND)                         \
   do {                                                      \
     __attribute__((assert_static_runtime(#COND), unused))   \
     int STATIC_PASTE1(assert_static_runtime_, __COUNTER__); \
-  } while(0)
+  } while(false)
 
 #else /* XGILL_PLUGIN */
 
 #define STATIC_PRECONDITION(COND)          /* nothing */
 #define STATIC_PRECONDITION_ASSUME(COND)   /* nothing */
 #define STATIC_POSTCONDITION(COND)         /* nothing */
 #define STATIC_POSTCONDITION_ASSUME(COND)  /* nothing */
 #define STATIC_INVARIANT(COND)             /* nothing */
 #define STATIC_INVARIANT_ASSUME(COND)      /* nothing */
 
-#define STATIC_ASSUME(COND)          do { /* nothing */ } while(0)
-#define STATIC_ASSERT_RUNTIME(COND)  do { /* nothing */ } while(0)
+#define STATIC_ASSUME(COND)          do { /* nothing */ } while(false)
+#define STATIC_ASSERT_RUNTIME(COND)  do { /* nothing */ } while(false)
 
 #endif /* XGILL_PLUGIN */
 
 #define STATIC_SKIP_INFERENCE STATIC_INVARIANT(skip_inference())
 
 #endif /* HAVE_STATIC_ANNOTATIONS */
 
 /******************************************************************************
@@ -224,28 +224,28 @@ inline void MOZ_PretendNoReturn()
  */
 
 #define NS_ENSURE_TRUE(x, ret)                                \
   do {                                                        \
     if (MOZ_UNLIKELY(!(x))) {                                 \
        NS_WARNING("NS_ENSURE_TRUE(" #x ") failed");           \
        return ret;                                            \
     }                                                         \
-  } while(0)
+  } while(false)
 
 #define NS_ENSURE_FALSE(x, ret)                               \
   NS_ENSURE_TRUE(!(x), ret)
 
 #define NS_ENSURE_TRUE_VOID(x)                                \
   do {                                                        \
     if (MOZ_UNLIKELY(!(x))) {                                 \
        NS_WARNING("NS_ENSURE_TRUE(" #x ") failed");           \
        return;                                                \
     }                                                         \
-  } while(0)
+  } while(false)
 
 #define NS_ENSURE_FALSE_VOID(x)                               \
   NS_ENSURE_TRUE_VOID(!(x))
 
 /******************************************************************************
 ** Macros for checking results
 ******************************************************************************/
 
@@ -275,26 +275,26 @@ inline void MOZ_PretendNoReturn()
 
 #define NS_ENSURE_SUCCESS(res, ret)                                       \
   do {                                                                    \
     nsresult __rv = res; /* Don't evaluate |res| more than once */        \
     if (NS_FAILED(__rv)) {                                                \
       NS_ENSURE_SUCCESS_BODY(res, ret)                                    \
       return ret;                                                         \
     }                                                                     \
-  } while(0)
+  } while(false)
 
 #define NS_ENSURE_SUCCESS_VOID(res)                                       \
   do {                                                                    \
     nsresult __rv = res;                                                  \
     if (NS_FAILED(__rv)) {                                                \
       NS_ENSURE_SUCCESS_BODY_VOID(res)                                    \
       return;                                                             \
     }                                                                     \
-  } while(0)
+  } while(false)
 
 /******************************************************************************
 ** Macros for checking state and arguments upon entering interface boundaries
 ******************************************************************************/
 
 #define NS_ENSURE_ARG(arg)                                    \
   NS_ENSURE_TRUE(arg, NS_ERROR_INVALID_ARG)