diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-25 05:02:21 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-25 05:02:21 +0000 |
commit | a0d3ca1ea5578bc736bb71bcec50ab41fefc87b9 (patch) | |
tree | 389626da7bc372df7e81749c6de20dbbe4c23e6b /lib/Sema/SemaStmt.cpp | |
parent | 0be3193b3bc695eb4b0debc7f85bc832026ce862 (diff) |
Refactor ActOnFinishSwitchStmt to simplify it further
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89843 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index a826c67291..b54de3e171 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -481,11 +481,6 @@ static bool CheckCXXSwitchCondition(Sema &S, SourceLocation SwitchLoc, return true; } } - CondType = CondExpr->getType(); - - // Integral promotions are performed. - if (CondType->isIntegralType() || CondType->isEnumeralType()) - S.UsualUnaryConversions(CondExpr); return false; } @@ -504,17 +499,12 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, Expr *CondExpr = SS->getCond(); QualType CondTypeBeforePromotion = GetTypeBeforeIntegralPromotion(CondExpr); - QualType CondType = CondExpr->getType(); - if (getLangOptions().CPlusPlus) { - if (CheckCXXSwitchCondition(*this, SwitchLoc, CondExpr)) + if (getLangOptions().CPlusPlus && + CheckCXXSwitchCondition(*this, SwitchLoc, CondExpr)) return StmtError(); - } else { - // C99 6.8.4.2p5 - Integer promotions are performed on the - // controlling expr. - UsualUnaryConversions(CondExpr); - } - CondType = CondExpr->getType(); + + QualType CondType = CondExpr->getType(); SS->setCond(CondExpr); // C++ 6.4.2.p2: @@ -531,6 +521,8 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, return StmtError(); } + UsualUnaryConversions(CondExpr); + if (CondTypeBeforePromotion->isBooleanType()) { // switch(bool_expr) {...} is often a programmer error, e.g. // switch(n && mask) { ... } // Doh - should be "n & mask". |