diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2012-01-13 23:41:25 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2012-01-13 23:41:25 +0000 |
| commit | c09e0557a548a3032c9de7915e9f10426efd9d70 (patch) | |
| tree | 70d92f5ce7c6a8ae02e01f625c348d7f85ee4b16 /clang/lib/Sema | |
| parent | 1c29e7297ae2ccea58e251d6a840cb8206da3aa5 (diff) | |
| download | bcm5719-llvm-c09e0557a548a3032c9de7915e9f10426efd9d70.tar.gz bcm5719-llvm-c09e0557a548a3032c9de7915e9f10426efd9d70.zip | |
Progress towards making isUsed() reflect whether a declaration is odr-used; don't set isUsed for local variables which are referenced in unevaluated contexts. Make other code use isReferenced() (which basically indicates that a declaration isn't dead) where appropriate.
I was forced to change test/SemaCXX/linkage.cpp because we aren't actually modeling extern "C" in the AST the way that testcase expects; we were not printing a warning only because we skipped the relevant check. Someone who actually understands the semantics here should fix that.
llvm-svn: 148158
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 10 |
2 files changed, 2 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 20309ee51cc..37cb9c9a70e 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1095,7 +1095,7 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) { if (D->isInvalidDecl()) return false; - if (D->isUsed() || D->hasAttr<UnusedAttr>()) + if (D->isReferenced() || D->isUsed() || D->hasAttr<UnusedAttr>()) return false; if (isa<LabelDecl>(D)) @@ -6804,7 +6804,7 @@ void Sema::DiagnoseUnusedParameters(ParmVarDecl * const *Param, return; for (; Param != ParamEnd; ++Param) { - if (!(*Param)->isUsed() && (*Param)->getDeclName() && + if (!(*Param)->isReferenced() && (*Param)->getDeclName() && !(*Param)->hasAttr<UnusedAttr>()) { Diag((*Param)->getLocation(), diag::warn_unused_parameter) << (*Param)->getDeclName(); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 8625d9b2601..15f56e840c5 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -9377,16 +9377,6 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) { if (D->isUsed(false)) return; - // Mark a parameter or variable declaration "used", regardless of whether - // we're in a template or not. The reason for this is that unevaluated - // expressions (e.g. (void)sizeof()) constitute a use for warning purposes - // (-Wunused-variables and -Wunused-parameters) - if (isa<ParmVarDecl>(D) || - (isa<VarDecl>(D) && D->getDeclContext()->isFunctionOrMethod())) { - D->setUsed(); - return; - } - if (!isa<VarDecl>(D) && !isa<FunctionDecl>(D)) return; |

