From 85970ca84cd6b3545b3b4a3ca5b6f7d87541ee38 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 10 Dec 2008 23:01:14 +0000 Subject: 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 --- clang/lib/Sema/SemaExprCXX.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'clang/lib/Sema/SemaExprCXX.cpp') 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((Decl *)Dcl)) + VD->setDeclaredInCondition(true); + return new CXXConditionDeclExpr(StartLoc, EqualLoc, cast(static_cast(Dcl))); } -- cgit v1.2.3