FullExprArg FullCond(Actions.FullExpr(Cond));
- OwningStmtResult Switch(Actions);
- if (!Cond.isInvalid() || CondVar.get())
- Switch = Actions.ActOnStartOfSwitchStmt(FullCond, CondVar);
+ OwningStmtResult Switch = Actions.ActOnStartOfSwitchStmt(FullCond, CondVar);
// C99 6.8.4p3 - In C99, the body of the switch statement is a scope, even if
// there is no compound stmt. C90 does not have this clause. We only do this
if (CondResult.isInvalid())
return StmtError();
}
- Expr *ConditionExpr = CondResult.takeAs<Expr>();
- if (!ConditionExpr)
- return StmtError();
-
- CondResult.release();
- SwitchStmt *SS = new (Context) SwitchStmt(ConditionVar, ConditionExpr);
+ SwitchStmt *SS = new (Context) SwitchStmt(ConditionVar,
+ CondResult.takeAs<Expr>());
getSwitchStack().push_back(SS);
return Owned(SS);
}
SS->setBody(BodyStmt, SwitchLoc);
getSwitchStack().pop_back();
+ if (SS->getCond() == 0) {
+ SS->Destroy(Context);
+ return StmtError();
+ }
+
Expr *CondExpr = SS->getCond();
QualType CondTypeBeforePromotion =
GetTypeBeforeIntegralPromotion(CondExpr);
// RUN: clang-cc -fsyntax-only -verify %s
-
void f (int z) {
while (z) {
default: z--; // expected-error {{statement not in switch}}
break;
}
}
+
+// PR5606
+int f0(int var) {
+ switch (va) { // expected-error{{use of undeclared identifier 'va'}}
+ case 1:
+ break;
+ case 2:
+ return 1;
+ }
+ return 2;
+}