diff options
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 21 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 4 |
2 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 8cbbca3fbf0..3870f0736ec 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -483,6 +483,27 @@ Sema::ExprResult Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, // check if referencing an identifier with __attribute__((deprecated)). if (VD->getAttr<DeprecatedAttr>()) Diag(Loc, diag::warn_deprecated) << VD->getDeclName(); + + if (VarDecl *Var = dyn_cast<VarDecl>(VD)) { + if (Var->isDeclaredInCondition() && Var->getType()->isScalarType()) { + Scope *CheckS = S; + while (CheckS) { + if (CheckS->isWithinElse() && + CheckS->getControlParent()->isDeclScope(Var)) { + if (Var->getType()->isBooleanType()) + Diag(Loc, diag::warn_value_always_false) << Var->getDeclName(); + else + Diag(Loc, diag::warn_value_always_zero) << Var->getDeclName(); + break; + } + + // Move up one more control parent to check again. + CheckS = CheckS->getControlParent(); + if (CheckS) + CheckS = CheckS->getParent(); + } + } + } // Only create DeclRefExpr's for valid Decl's. if (VD->isInvalidDecl()) 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))); } |

