aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r--lib/Sema/SemaStmt.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index ad3376b9c8..cecc9b32c1 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -242,8 +242,17 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal,
OwningExprResult CondResult(CondVal.release());
Expr *condExpr = CondResult.takeAs<Expr>();
-
assert(condExpr && "ActOnIfStmt(): missing expression");
+
+ 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
+ }
+
if (CheckBooleanCondition(condExpr, IfLoc)) {
CondResult = condExpr;
return StmtError();
@@ -265,7 +274,7 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal,
DiagnoseUnusedExprResult(elseStmt);
CondResult.release();
- return Owned(new (Context) IfStmt(IfLoc, condExpr, thenStmt,
+ return Owned(new (Context) IfStmt(IfLoc, ConditionVar, condExpr, thenStmt,
ElseLoc, elseStmt));
}