]> granicus.if.org Git - clang/commitdiff
Fix a missed case in the NULL operand to conditional operator
authorChandler Carruth <chandlerc@gmail.com>
Sat, 19 Feb 2011 00:13:59 +0000 (00:13 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sat, 19 Feb 2011 00:13:59 +0000 (00:13 +0000)
diagnostics.

Patch by Stephen Hines.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125998 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/conditional-expr.cpp
test/SemaCXX/nullptr.cpp

index b78e52303e1cfa8cd38f50e3c19a820bfaca599d..9113f8a4621eb0a2014549fa400e1a8dcfa55ae2 100644 (file)
@@ -3141,6 +3141,10 @@ QualType Sema::CXXCheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS,
   if (!Composite.isNull())
     return Composite;
 
+  // Check if we are using a null with a non-pointer type.
+  if (DiagnoseConditionalForNull(LHS, RHS, QuestionLoc))
+    return QualType();
+
   Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
     << LHS->getType() << RHS->getType()
     << LHS->getSourceRange() << RHS->getSourceRange();
index 3881765cff33cc84f440243cdb01e2ac4df83fbd..5637ed14c0a6245b9aafa268889c6d22eb3363fe 100644 (file)
@@ -311,10 +311,12 @@ namespace PR7598 {
 namespace PR9236 {
 #define NULL 0L
   void f() {
+    int i;
     (void)(true ? A() : NULL); // expected-error{{non-pointer operand type 'A' incompatible with NULL}}
     (void)(true ? NULL : A()); // expected-error{{non-pointer operand type 'A' incompatible with NULL}}
     (void)(true ? 0 : A()); // expected-error{{incompatible operand types}}
     (void)(true ? nullptr : A()); // expected-error{{non-pointer operand type 'A' incompatible with nullptr}}
+    (void)(true ? nullptr : i); // expected-error{{non-pointer operand type 'int' incompatible with nullptr}}
     (void)(true ? __null : A()); // expected-error{{non-pointer operand type 'A' incompatible with NULL}}
     (void)(true ? (void*)0 : A()); // expected-error{{incompatible operand types}}
   }
index 7385fd42ad38a5807f656f612b7e83ecafbb9e89..1c454771aaa1e0fc6422a9ff4bfebce886c9cd30 100644 (file)
@@ -44,7 +44,7 @@ nullptr_t f(nullptr_t null)
   (void)(1 > nullptr); // expected-error {{invalid operands to binary expression}}
   (void)(1 != nullptr); // expected-error {{invalid operands to binary expression}}
   (void)(1 + nullptr); // expected-error {{invalid operands to binary expression}}
-  (void)(0 ? nullptr : 0); // expected-error {{incompatible operand types}}
+  (void)(0 ? nullptr : 0); // expected-error {{non-pointer operand type 'int' incompatible with nullptr}}
   (void)(0 ? nullptr : (void*)0);
   (void)(0 ? nullptr : A()); // expected-error {{non-pointer operand type 'A' incompatible with nullptr}}
   (void)(0 ? A() : nullptr); // expected-error {{non-pointer operand type 'A' incompatible with nullptr}}