diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-13 18:42:40 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-13 18:42:40 +0000 |
commit | 30c0dd86f0dc3c1a1fba29581d04e8ed0bdb659d (patch) | |
tree | 408d41d6a1f30e44706c5c87f51c0531767a653c /lib/Sema/Sema.cpp | |
parent | f6d1d43d68016e975f22264343631a55b9701495 (diff) |
The unused warnings extravaganza continues. Warn for:
-static variables
-variables in anonymous namespace (fixes rdar://7794535)
-static data members in anonymous namespace
-static data members specializations in anonymous namespace
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111027 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/Sema.cpp')
-rw-r--r-- | lib/Sema/Sema.cpp | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 76e059138e..df9bb07cf9 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -241,15 +241,33 @@ static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) { return true; if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { - // For functions, UnusedFileScopedDecls stores the first declaration. + // UnusedFileScopedDecls stores the first declaration. + // The declaration may have become definition so check again. + const FunctionDecl *DeclToCheck; + if (FD->hasBody(DeclToCheck)) + return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); + // Later redecls may add new information resulting in not having to warn, // so check again. - const FunctionDecl *DeclToCheck; - if (!FD->hasBody(DeclToCheck)) - DeclToCheck = FD->getMostRecentDeclaration(); + DeclToCheck = FD->getMostRecentDeclaration(); if (DeclToCheck != FD) return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); } + + if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { + // UnusedFileScopedDecls stores the first declaration. + // The declaration may have become definition so check again. + const VarDecl *DeclToCheck = VD->getDefinition(); + if (DeclToCheck) + return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); + + // Later redecls may add new information resulting in not having to warn, + // so check again. + DeclToCheck = VD->getMostRecentDeclaration(); + if (DeclToCheck != VD) + return !SemaRef->ShouldWarnIfUnusedFileScopedDecl(DeclToCheck); + } + return false; } @@ -358,9 +376,13 @@ void Sema::ActOnEndOfTranslationUnit() { DiagD = FD; Diag(DiagD->getLocation(), diag::warn_unused_function) << DiagD->getDeclName(); - } else - Diag((*I)->getLocation(), diag::warn_unused_variable) - << cast<VarDecl>(*I)->getDeclName(); + } else { + const VarDecl *DiagD = cast<VarDecl>(*I)->getDefinition(); + if (!DiagD) + DiagD = cast<VarDecl>(*I); + Diag(DiagD->getLocation(), diag::warn_unused_variable) + << DiagD->getDeclName(); + } } } |