diff options
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Sema/TreeTransform.h | 13 |
2 files changed, 23 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index cecc9b32c10..6ff3d638fe9 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -280,7 +280,17 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Action::OwningStmtResult Sema::ActOnStartOfSwitchStmt(ExprArg cond) { - SwitchStmt *SS = new (Context) SwitchStmt(cond.takeAs<Expr>()); + Expr *condExpr = cond.takeAs<Expr>(); + VarDecl *ConditionVar = 0; + if (CXXConditionDeclExpr *Cond = dyn_cast<CXXConditionDeclExpr>(condExpr)) { + ConditionVar = Cond->getVarDecl(); + condExpr = DeclRefExpr::Create(Context, 0, SourceRange(), ConditionVar, + ConditionVar->getLocation(), + ConditionVar->getType().getNonReferenceType()); + // FIXME: Leaks the old condExpr + } + + SwitchStmt *SS = new (Context) SwitchStmt(ConditionVar, condExpr); getSwitchStack().push_back(SS); return Owned(SS); } diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index d226c1eb5c2..a7a9cfaca84 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -3126,7 +3126,18 @@ template<typename Derived> Sema::OwningStmtResult TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { // Transform the condition. - OwningExprResult Cond = getDerived().TransformExpr(S->getCond()); + OwningExprResult Cond(SemaRef); + VarDecl *ConditionVar = 0; + if (S->getConditionVariable()) { + ConditionVar + = cast_or_null<VarDecl>( + getDerived().TransformDefinition(S->getConditionVariable())); + if (!ConditionVar) + return SemaRef.StmtError(); + + Cond = getSema().CheckConditionVariable(ConditionVar); + } else + Cond = getDerived().TransformExpr(S->getCond()); if (Cond.isInvalid()) return SemaRef.StmtError(); |