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 | 110755548b1d523a49bda2b35b54a0e6a42b418f (patch) | |
| tree | 5afa3095581703fb0b4360c8ed119debc68b09a8 /clang/lib/Sema/SemaStmt.cpp | |
| parent | 852d53e71207e7a28d42ef67882bd95d06f5558e (diff) | |
| download | bcm5719-llvm-110755548b1d523a49bda2b35b54a0e6a42b418f.tar.gz bcm5719-llvm-110755548b1d523a49bda2b35b54a0e6a42b418f.zip | |
Refactor ActOnFinishSwitchStmt to simplify it further
llvm-svn: 89843
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index a826c672914..b54de3e1711 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/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". |

