[cfe-commits] r51957 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/conditional.c

Nuno Lopes nunoplopes at sapo.pt
Wed Jun 4 12:14:12 PDT 2008


Author: nlopes
Date: Wed Jun  4 14:14:12 2008
New Revision: 51957

URL: http://llvm.org/viewvc/llvm-project?rev=51957&view=rev
Log:
fix type of ?: operator. If one of the operator is void, the type should be void as well.
Please confirm this is safe

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/conditional.c

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=51957&r1=51956&r2=51957&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jun  4 14:14:12 2008
@@ -917,12 +917,14 @@
   // C99 6.5.15p5: "If both operands have void type, the result has void type."
   // The following || allows only one side to be void (a GCC-ism).
   if (lexT->isVoidType() || rexT->isVoidType()) {
-    if (!lexT->isVoidType())
+    if (!lexT->isVoidType()) {
       Diag(rex->getLocStart(), diag::ext_typecheck_cond_one_void, 
            rex->getSourceRange());
+      return rexT.getUnqualifiedType();
+    }
     if (!rexT->isVoidType())
       Diag(lex->getLocStart(), diag::ext_typecheck_cond_one_void,
-           lex->getSourceRange());    
+           lex->getSourceRange());
     return lexT.getUnqualifiedType();
   }
   // C99 6.5.15p6 - "if one operand is a null pointer constant, the result has

Modified: cfe/trunk/test/Sema/conditional.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/conditional.c?rev=51957&r1=51956&r2=51957&view=diff

==============================================================================
--- cfe/trunk/test/Sema/conditional.c (original)
+++ cfe/trunk/test/Sema/conditional.c Wed Jun  4 14:14:12 2008
@@ -1,4 +1,15 @@
-// RUN: clang %s -fsyntax-only
+// RUN: clang %s -fsyntax-only -verify
 
 const char* test1 = 1 ? "i" : 1 == 1 ? "v" : "r";
 
+void _efree(void *ptr);
+
+int _php_stream_free1()
+{
+	return (1 ? free(0) : _efree(0)); // expected-error {{incompatible type returning 'void', expected 'int'}}
+}
+
+int _php_stream_free2()
+{
+	return (1 ? _efree(0) : free(0));  // expected-error {{incompatible type returning 'void', expected 'int'}}
+}





More information about the cfe-commits mailing list