Avoid MSVC's C6323 warning (use of arithmetic operator on Boolean type)
authorSven Panne <svenpanne@chromium.org>
Tue, 13 Jan 2015 10:52:29 +0000 (11:52 +0100)
committerSven Panne <svenpanne@chromium.org>
Tue, 13 Jan 2015 10:52:44 +0000 (10:52 +0000)
We could use BoolToInt consistently, but for now let's just fix the warnings.

R=jochen@chromium.org

Review URL: https://codereview.chromium.org/825913005

Cr-Commit-Position: refs/heads/master@{#26037}

src/date.cc
src/runtime/runtime-scopes.cc
src/utils.h

index 6b95cb7..1f879de 100644 (file)
@@ -103,8 +103,8 @@ void DateCache::YearMonthDayFromDays(
   days += is_leap;
 
   // Check if the date is after February.
-  if (days >= 31 + 28 + is_leap) {
-    days -= 31 + 28 + is_leap;
+  if (days >= 31 + 28 + BoolToInt(is_leap)) {
+    days -= 31 + 28 + BoolToInt(is_leap);
     // Find the date starting from March.
     for (int i = 2; i < 12; i++) {
       if (days < kDaysInMonths[i]) {
index 2a0b435..352e9ef 100644 (file)
@@ -106,7 +106,8 @@ RUNTIME_FUNCTION(Runtime_DeclareGlobals) {
     bool is_var = initial_value->IsUndefined();
     bool is_const = initial_value->IsTheHole();
     bool is_function = initial_value->IsSharedFunctionInfo();
-    DCHECK(is_var + is_const + is_function == 1);
+    DCHECK_EQ(1,
+              BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function));
 
     Handle<Object> value;
     if (is_function) {
@@ -220,7 +221,8 @@ RUNTIME_FUNCTION(Runtime_DeclareLookupSlot) {
   bool is_var = *initial_value == NULL;
   bool is_const = initial_value->IsTheHole();
   bool is_function = initial_value->IsJSFunction();
-  DCHECK(is_var + is_const + is_function == 1);
+  DCHECK_EQ(1,
+            BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function));
 
   int index;
   PropertyAttributes attributes;
index 525c6f8..87276c1 100644 (file)
@@ -27,6 +27,9 @@ namespace internal {
 // General helper functions
 
 
+inline int BoolToInt(bool b) { return b ? 1 : 0; }
+
+
 // Same as strcmp, but can handle NULL arguments.
 inline bool CStringEquals(const char* s1, const char* s2) {
   return (s1 == s2) || (s1 != NULL && s2 != NULL && strcmp(s1, s2) == 0);