diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-13 18:42:29 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-13 18:42:29 +0000 |
commit | 540bc01f500e353d3233edb799b1b5d868633c48 (patch) | |
tree | 1d84c58136922739a7fe41e2443c10da8e781630 /clang/lib/Sema/SemaDecl.cpp | |
parent | 35672e78523162ab292962ce5aec3f512ee5cf8a (diff) | |
download | bcm5719-llvm-540bc01f500e353d3233edb799b1b5d868633c48.tar.gz bcm5719-llvm-540bc01f500e353d3233edb799b1b5d868633c48.zip |
Expand the unused warnings for functions. Warn for:
-static function declarations
-functions in anonymous namespace
-class methods in anonymous namespace
-class method specializations in anonymous namespace
-function specializations in anonymous namespace
llvm-svn: 111026
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index e1f9c82feca..cf6f20f60ae 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -521,25 +521,40 @@ static void RemoveUsingDecls(LookupResult &R) { F.done(); } -static bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) { +bool Sema::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const { + assert(D); + if (D->isInvalidDecl() || D->isUsed() || D->hasAttr<UnusedAttr>()) + return false; + if (D->getLinkage() == ExternalLinkage) + return false; + + // Ignore class templates. + if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) + if (MD->getParent()->getDescribedClassTemplate()) + return false; + + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { + if (FD->isThisDeclarationADefinition()) + return !Context.DeclMustBeEmitted(FD); + return true; + } + + return false; + } + + void Sema::MarkUnusedFileScopedDecl(const DeclaratorDecl *D) { + if (!D) + return; + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { - // Warn for static, non-inlined function definitions that - // have not been used. - // FIXME: Also include static functions declared but not defined. - return (!FD->isInvalidDecl() - && !FD->isInlined() && FD->getLinkage() == InternalLinkage - && !FD->isUsed() && !FD->hasAttr<UnusedAttr>() - && !FD->hasAttr<ConstructorAttr>() - && !FD->hasAttr<DestructorAttr>()); + const FunctionDecl *First = FD->getFirstDeclaration(); + if (FD != First && ShouldWarnIfUnusedFileScopedDecl(First)) + return; // First should already be in the vector. } - - return false; -} -void Sema::MarkUnusedFileScopedDecl(const DeclaratorDecl *D) { - if (ShouldWarnIfUnusedFileScopedDecl(D)) - UnusedFileScopedDecls.push_back(D); -} + if (ShouldWarnIfUnusedFileScopedDecl(D)) + UnusedFileScopedDecls.push_back(D); + } static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) { if (D->isInvalidDecl()) @@ -3638,8 +3653,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, if (FunctionTemplate) return FunctionTemplate; - if (IsFunctionDefinition) - MarkUnusedFileScopedDecl(NewFD); + MarkUnusedFileScopedDecl(NewFD); return NewFD; } |