Added a warning when referencing an if's condition variable in the
"else" clause, e.g.,
if (int X = foo()) {
} else {
if (X) { // warning: X is always zero in this context
}
}
Fixes rdar://6425550 and lets me think about something other than
DeclContext.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60858 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index c4cab33..27b0ba3 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -648,6 +648,10 @@
return true;
AddInitializerToDecl(Dcl, AssignExprVal);
+ // Mark this variable as one that is declared within a conditional.
+ if (VarDecl *VD = dyn_cast<VarDecl>((Decl *)Dcl))
+ VD->setDeclaredInCondition(true);
+
return new CXXConditionDeclExpr(StartLoc, EqualLoc,
cast<VarDecl>(static_cast<Decl *>(Dcl)));
}