diff options
author | Steve Naroff <snaroff@apple.com> | 2008-01-08 01:11:38 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2008-01-08 01:11:38 +0000 |
commit | 039ad3cf9017ee9d15103aa5fa27e3e6d7ea4a78 (patch) | |
tree | 2f069dcfb8c436c5d6cab86f72e6f6b08b13f097 /clang/Sema/SemaExpr.cpp | |
parent | 3b6fe5fa8d88c9f128f3358b7da12cc6a7ef14ac (diff) | |
download | bcm5719-llvm-039ad3cf9017ee9d15103aa5fa27e3e6d7ea4a78.tar.gz bcm5719-llvm-039ad3cf9017ee9d15103aa5fa27e3e6d7ea4a78.zip |
Fix Sema::CheckConditionalOperands(). The null pointer constant checks need to precede the check for two pointer operands.
llvm-svn: 45732
Diffstat (limited to 'clang/Sema/SemaExpr.cpp')
-rw-r--r-- | clang/Sema/SemaExpr.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp index cff4908edef..7d224c5e802 100644 --- a/clang/Sema/SemaExpr.cpp +++ b/clang/Sema/SemaExpr.cpp @@ -788,7 +788,17 @@ 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()) 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)) { + promoteExprToType(rex, lexT); // promote the null to a pointer. + return lexT; + } + if (rexT->isPointerType() && lex->isNullPointerConstant(Context)) { + promoteExprToType(lex, rexT); // promote the null to a pointer. + return rexT; + } // Handle the case where both operands are pointers before we handle null // pointer constants in case both operands are null pointer constants. if (const PointerType *LHSPT = lexT->getAsPointerType()) { // C99 6.5.15p3,6 @@ -822,18 +832,6 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15 } } - // 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)) { - promoteExprToType(rex, lexT); // promote the null to a pointer. - return lexT; - } - - if (rexT->isPointerType() && lex->isNullPointerConstant(Context)) { - promoteExprToType(lex, rexT); // promote the null to a pointer. - return rexT; - } - // Otherwise, the operands are not compatible. Diag(questionLoc, diag::err_typecheck_cond_incompatible_operands, lexT.getAsString(), rexT.getAsString(), |