]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/5928590> clang -fsyntax-only: "incompatible operand types ('int...
authorSteve Naroff <snaroff@apple.com>
Mon, 12 May 2008 21:44:38 +0000 (21:44 +0000)
committerSteve Naroff <snaroff@apple.com>
Mon, 12 May 2008 21:44:38 +0000 (21:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51002 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticKinds.def
lib/Sema/SemaExpr.cpp
test/Sema/conditional-expr.c

index 38322cbbc761b923653928bc0af21f469dba1249..2063fb45228ba52bb5854e68566e45ea883a2080 100644 (file)
@@ -904,6 +904,8 @@ DIAG(err_typecheck_call_invalid_ordered_compare, ERROR,
      "ordered compare requires two args of floating point type ('%0' and '%1')")
 DIAG(err_typecheck_cond_expect_scalar, ERROR,
      "used type '%0' where arithmetic or pointer type is required")
+DIAG(ext_typecheck_cond_one_void, EXTENSION,
+     "C99 forbids conditional expressions with only one void side")
 DIAG(err_typecheck_expect_scalar_operand, ERROR,
      "operand of type '%0' where arithmetic or pointer type is required")
 DIAG(err_typecheck_cond_incompatible_operands, ERROR,
index 5341ee7faa3f34f31a71942b2b0346d350f3e356..68a3f8d5936532d006fce8e34f3a9e551debfffc 100644 (file)
@@ -856,9 +856,16 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
   }
   
   // C99 6.5.15p5: "If both operands have void type, the result has void type."
-  if (lexT->isVoidType() && rexT->isVoidType())
+  // The following || allows only one side to be void (a GCC-ism).
+  if (lexT->isVoidType() || rexT->isVoidType()) {
+    if (!lexT->isVoidType())
+      Diag(rex->getLocStart(), diag::ext_typecheck_cond_one_void, 
+           rex->getSourceRange());
+    if (!rexT->isVoidType())
+      Diag(lex->getLocStart(), diag::ext_typecheck_cond_one_void,
+           lex->getSourceRange());    
     return lexT.getUnqualifiedType();
-
+  }
   // C99 6.5.15p6 - "if one operand is a null pointer constant, the result has
   // the type of the other operand."
   if (lexT->isPointerType() && rex->isNullPointerConstant(Context)) {
index a21914c6d5ccb6b0aa200bc5d72c7ab2387a0725..ae973d6b2b8494864c1dc7b06f1feb881052f486 100644 (file)
@@ -36,3 +36,7 @@ void foo() {
   *(0 ? (asdf) 0 : &x) = 10;
 }
 
+int Postgresql() {
+  char x;
+  return ((((&x) != ((void *) 0)) ? (*(&x) = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
+}