forked from OSchip/llvm-project
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
This commit is contained in:
parent
6e59392e4b
commit
28bcfec325
|
@ -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
|
||||
|
|
|
@ -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'}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue