Built-in equality and relational operators have return type "bool" in C++,
not "int".

Fix a typo in the promotion of enumeration types that was causing some
integral promotions to look like integral conversions (leading to
extra ambiguities in overload resolution).

Check for "acceptable" overloaded operators based on the types of the
arguments. This is a somewhat odd check that is specified by the
standard, but I can't see why it actually matters: the overload
candidates it suppresses don't seem like they would ever be picked as
the best candidates.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59583 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 960c99a..0e62e26 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2145,9 +2145,12 @@
           Diag(Loc, diag::warn_selfcomparison);      
   }
   
+  // The result of comparisons is 'bool' in C++, 'int' in C.
+  QualType ResultTy = getLangOptions().CPlusPlus? Context.BoolTy : Context.IntTy;
+
   if (isRelational) {
     if (lType->isRealType() && rType->isRealType())
-      return Context.IntTy;
+      return ResultTy;
   } else {
     // Check for comparisons of floating point operands using != and ==.
     if (lType->isFloatingType()) {
@@ -2156,7 +2159,7 @@
     }
     
     if (lType->isArithmeticType() && rType->isArithmeticType())
-      return Context.IntTy;
+      return ResultTy;
   }
   
   bool LHSIsNull = lex->isNullPointerConstant(Context);
@@ -2181,7 +2184,7 @@
         << lex->getSourceRange() << rex->getSourceRange();
     }
     ImpCastExprToType(rex, lType); // promote the pointer to pointer
-    return Context.IntTy;
+    return ResultTy;
   }
   // Handle block pointer types.
   if (lType->isBlockPointerType() && rType->isBlockPointerType()) {
@@ -2195,7 +2198,7 @@
         << lex->getSourceRange() << rex->getSourceRange();
     }
     ImpCastExprToType(rex, lType); // promote the pointer to pointer
-    return Context.IntTy;
+    return ResultTy;
   }
   // Allow block pointers to be compared with null pointer constants.
   if ((lType->isBlockPointerType() && rType->isPointerType()) ||
@@ -2206,7 +2209,7 @@
         << lex->getSourceRange() << rex->getSourceRange();
     }
     ImpCastExprToType(rex, lType); // promote the pointer to pointer
-    return Context.IntTy;
+    return ResultTy;
   }
 
   if ((lType->isObjCQualifiedIdType() || rType->isObjCQualifiedIdType())) {
@@ -2224,21 +2227,21 @@
           << lType.getAsString() << rType.getAsString()
           << lex->getSourceRange() << rex->getSourceRange();
         ImpCastExprToType(rex, lType);
-        return Context.IntTy;
+        return ResultTy;
       }
       ImpCastExprToType(rex, lType);
-      return Context.IntTy;
+      return ResultTy;
     }
     if (ObjCQualifiedIdTypesAreCompatible(lType, rType, true)) {
       ImpCastExprToType(rex, lType);
-      return Context.IntTy;
+      return ResultTy;
     } else {
       if ((lType->isObjCQualifiedIdType() && rType->isObjCQualifiedIdType())) {
         Diag(Loc, diag::warn_incompatible_qualified_id_operands)
           << lType.getAsString() << rType.getAsString()
           << lex->getSourceRange() << rex->getSourceRange();
         ImpCastExprToType(rex, lType);
-        return Context.IntTy;
+        return ResultTy;
       }
     }
   }
@@ -2249,7 +2252,7 @@
         << lType.getAsString() << rType.getAsString()
         << lex->getSourceRange() << rex->getSourceRange();
     ImpCastExprToType(rex, lType); // promote the integer to pointer
-    return Context.IntTy;
+    return ResultTy;
   }
   if (lType->isIntegerType() && 
       (rType->isPointerType() || rType->isObjCQualifiedIdType())) {
@@ -2258,7 +2261,7 @@
         << lType.getAsString() << rType.getAsString()
         << lex->getSourceRange() << rex->getSourceRange();
     ImpCastExprToType(lex, rType); // promote the integer to pointer
-    return Context.IntTy;
+    return ResultTy;
   }
   // Handle block pointers.
   if (lType->isBlockPointerType() && rType->isIntegerType()) {
@@ -2267,7 +2270,7 @@
         << lType.getAsString() << rType.getAsString()
         << lex->getSourceRange() << rex->getSourceRange();
     ImpCastExprToType(rex, lType); // promote the integer to pointer
-    return Context.IntTy;
+    return ResultTy;
   }
   if (lType->isIntegerType() && rType->isBlockPointerType()) {
     if (!LHSIsNull)
@@ -2275,7 +2278,7 @@
         << lType.getAsString() << rType.getAsString()
         << lex->getSourceRange() << rex->getSourceRange();
     ImpCastExprToType(lex, rType); // promote the integer to pointer
-    return Context.IntTy;
+    return ResultTy;
   }
   return InvalidOperands(Loc, lex, rex);
 }