]> granicus.if.org Git - clang/commitdiff
Fix a thinko where we weren't always performing unary conversions on the switch condi...
authorDouglas Gregor <dgregor@apple.com>
Wed, 25 Nov 2009 15:17:36 +0000 (15:17 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 25 Nov 2009 15:17:36 +0000 (15:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89864 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaStmt.cpp

index e2b065bb9051b4d203ccf02aca794a1c3697e464..de67a5f1a75fa74051b45b42d0644c6202b1ced9 100644 (file)
@@ -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".