diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-01-06 22:42:25 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-01-06 22:42:25 +0000 |
| commit | e2949f42d3485033230727889a619c5f5b7984e0 (patch) | |
| tree | 8646c12fc915a72c72e1c682d8b8e3fd8e7b2ff3 | |
| parent | cfb6f430b60b79a3f4137d4959f1722fbc0d5e41 (diff) | |
| download | bcm5719-llvm-e2949f42d3485033230727889a619c5f5b7984e0.tar.gz bcm5719-llvm-e2949f42d3485033230727889a619c5f5b7984e0.zip | |
some simplifications/cleanups to ?: sema.
llvm-svn: 45665
| -rw-r--r-- | clang/Sema/SemaExpr.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp index 78180be4978..dcbfe78a41f 100644 --- a/clang/Sema/SemaExpr.cpp +++ b/clang/Sema/SemaExpr.cpp @@ -765,23 +765,32 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15 condT.getAsString()); return QualType(); } - // now check the two expressions. - if (lexT->isArithmeticType() && rexT->isArithmeticType()) { // C99 6.5.15p3,5 + + // Now check the two expressions. + + // If both operands have arithmetic type, do the usual arithmetic conversions + // to find a common type: C99 6.5.15p3,5. + if (lexT->isArithmeticType() && rexT->isArithmeticType()) { UsualArithmeticConversions(lex, rex); return lex->getType(); } + + // If both operands are the same structure or union type, the result is that + // type. if (const RecordType *LHSRT = lexT->getAsRecordType()) { // C99 6.5.15p3 - if (const RecordType *RHSRT = rexT->getAsRecordType()) { + if (const RecordType *RHSRT = rexT->getAsRecordType()) if (LHSRT->getDecl() == RHSRT->getDecl()) - return lexT; - - Diag(questionLoc, diag::err_typecheck_cond_incompatible_operands, - lexT.getAsString(), rexT.getAsString(), - lex->getSourceRange(), rex->getSourceRange()); - return QualType(); - } + // "If both the operands have structure or union type, the result has + // that type." This implies that CV qualifiers are dropped. + return lexT.getUnqualifiedType(); } - // C99 6.5.15p3 + + // 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; @@ -820,9 +829,7 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15 } } - if (lexT->isVoidType() && rexT->isVoidType()) // C99 6.5.15p3 - return lexT; - + // Otherwise, the operands are not compatible. Diag(questionLoc, diag::err_typecheck_cond_incompatible_operands, lexT.getAsString(), rexT.getAsString(), lex->getSourceRange(), rex->getSourceRange()); |

