]> granicus.if.org Git - clang/commitdiff
Re-improve recovery when the condition of a switch statement does not
authorDouglas Gregor <dgregor@apple.com>
Tue, 29 Jun 2010 23:25:20 +0000 (23:25 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 29 Jun 2010 23:25:20 +0000 (23:25 +0000)
have integral or enumeration type, so that we still check the contents
of the switch body. My previous patch made this worse; now we're back
to where we were previously.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107223 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp
lib/Sema/SemaStmt.cpp
test/Sema/complex-int.c

index af28d46b5fe77a1df9fe0dfde92717137b900e21..86724f9a92fa3e9d0eb69c7f43296e37d75c7e1a 100644 (file)
@@ -3106,7 +3106,7 @@ Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, ExprArg FromE,
   if (!RecordTy || !getLangOptions().CPlusPlus) {
     Diag(Loc, NotIntDiag)
       << T << From->getSourceRange();
-    return ExprError();
+    return move(FromE);
   }
     
   // We must have a complete class type.
@@ -3190,14 +3190,12 @@ Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, ExprArg FromE,
       Diag(Conv->getLocation(), AmbigNote)
         << ConvTy->isEnumeralType() << ConvTy;
     }
-    return ExprError();
+    return move(FromE);
   }
   
-  if (!From->getType()->isIntegralOrEnumerationType()) {
+  if (!From->getType()->isIntegralOrEnumerationType())
     Diag(Loc, NotIntDiag)
       << From->getType() << From->getSourceRange();
-    return ExprError();
-  }
 
   return move(FromE);
 }
index fed30e4e5604822518f98bcc19aa63ddf5fa18eb..efd74e3c25571d901df72fe3e281357c9dd08c0b 100644 (file)
@@ -486,11 +486,11 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch,
   // be represented by the promoted type.  Therefore we need to find
   // the pre-promotion type of the switch condition.
   if (!CondExpr->isTypeDependent()) {
-    if (!CondType->isIntegerType()) { // C99 6.8.4.2p1
-      Diag(SwitchLoc, diag::err_typecheck_statement_requires_integer)
-          << CondType << CondExpr->getSourceRange();
+    // We have already converted the expression to an integral or enumeration
+    // type, when we started the switch statement. If we don't have an 
+    // appropriate type now, just return an error.
+    if (!CondType->isIntegralOrEnumerationType())
       return StmtError();
-    }
 
     if (CondExpr->isKnownToHaveBooleanValue()) {
       // switch(bool_expr) {...} is often a programmer error, e.g.
index bcd9939b29324ce81136da4f37d049f42c38fa97..cb76a342c2d0e0c7dca0a3d573a705213305742a 100644 (file)
@@ -16,13 +16,9 @@ result = arr*brr;
 result = xx*yy;
 
 switch (arr) { // expected-error{{statement requires expression of integer type ('_Complex int' invalid)}}
- default: ;
-}
-
- switch (ii) {
   case brr: ; // expected-error{{expression is not an integer constant expression}}
   case xx: ; // expected-error{{expression is not an integer constant expression}}
- }
+}
 }
 
 void Tester() {