summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2008-06-04 19:14:12 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2008-06-04 19:14:12 +0000
commit28bcfec325775f63dda9450314babd2f3bbee856 (patch)
treeafa914d3727d722ce80028a830ad67504ae58d87 /clang
parent6e59392e4bbd56cbfda9aaba9632a9701803677d (diff)
downloadbcm5719-llvm-28bcfec325775f63dda9450314babd2f3bbee856.tar.gz
bcm5719-llvm-28bcfec325775f63dda9450314babd2f3bbee856.zip
fix type of ?: operator. If one of the operator is void, the type should be void as well.
Please confirm this is safe llvm-svn: 51957
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp6
-rw-r--r--clang/test/Sema/conditional.c13
2 files changed, 16 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ecc1f2b001f..4673ae498fd 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -917,12 +917,14 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
// 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
diff --git a/clang/test/Sema/conditional.c b/clang/test/Sema/conditional.c
index 3af0fe57b43..e1ad1a51ba9 100644
--- a/clang/test/Sema/conditional.c
+++ b/clang/test/Sema/conditional.c
@@ -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'}}
+}
OpenPOWER on IntegriCloud