diff options
author | Douglas Gregor <dgregor@apple.com> | 2008-12-10 23:01:14 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2008-12-10 23:01:14 +0000 |
commit | 85970ca84cd6b3545b3b4a3ca5b6f7d87541ee38 (patch) | |
tree | 7e814814f679a0d4d23c66c028a0daa47e3b5804 /clang/lib/Sema/SemaExprCXX.cpp | |
parent | 0864a75ebf82c239ab62bdc91ee2fd3b7279245f (diff) | |
download | bcm5719-llvm-85970ca84cd6b3545b3b4a3ca5b6f7d87541ee38.tar.gz bcm5719-llvm-85970ca84cd6b3545b3b4a3ca5b6f7d87541ee38.zip |
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.
llvm-svn: 60858
Diffstat (limited to 'clang/lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index c4cab3316ba..27b0ba34d19 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -648,6 +648,10 @@ Sema::ActOnCXXConditionDeclarationExpr(Scope *S, SourceLocation StartLoc, 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))); } |