From: Douglas Gregor Date: Wed, 25 Nov 2009 15:17:36 +0000 (+0000) Subject: Fix a thinko where we weren't always performing unary conversions on the switch condi... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0de55e7e6b8a53c5d1f2e9a811fd0a4ea13ed5b0;p=clang Fix a thinko where we weren't always performing unary conversions on the switch condition, fixing PR5612 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89864 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index e2b065bb90..de67a5f1a7 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -501,10 +501,12 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, QualType CondTypeBeforePromotion = GetTypeBeforeIntegralPromotion(CondExpr); - if (getLangOptions().CPlusPlus && + if (getLangOptions().CPlusPlus && CheckCXXSwitchCondition(*this, SwitchLoc, CondExpr)) - return StmtError(); + return StmtError(); + // C99 6.8.4.2p5 - Integer promotions are performed on the controlling expr. + UsualUnaryConversions(CondExpr); QualType CondType = CondExpr->getType(); SS->setCond(CondExpr); @@ -522,8 +524,6 @@ 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".