summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-06-27 07:51:25 +0200
committerStephan Bergmann <sbergman@redhat.com>2014-06-27 07:51:51 +0200
commit9a741fcad458875a806295ddbd41b68d82ce9095 (patch)
tree9d8ed908f43b459e221aef8a7d1da4b043ebbe40 /compilerplugins
parent3c6e378fd81b2bfd8a35e12557a90fa40428920e (diff)
loplugin:unreffun: also warn about unused function templates
Change-Id: I4a6280f47ca3c4a77b4e42fe05d79ded7fc30ef1
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/unreffun.cxx23
1 files changed, 14 insertions, 9 deletions
diff --git a/compilerplugins/clang/unreffun.cxx b/compilerplugins/clang/unreffun.cxx
index eece97f17436..8c726e3d0845 100644
--- a/compilerplugins/clang/unreffun.cxx
+++ b/compilerplugins/clang/unreffun.cxx
@@ -60,12 +60,12 @@ bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) {
return true;
}
- //TODO, filtering out anything template for now:
- if (decl->isDependentContext()) {
- return true;
- }
+ //TODO, filtering out any functions relating to (class) templates for now:
CXXRecordDecl const * r = dyn_cast<CXXRecordDecl>(decl->getDeclContext());;
- if (r != nullptr && r->getTemplateSpecializationKind() != TSK_Undeclared) {
+ if (r != nullptr
+ && (r->getTemplateSpecializationKind() != TSK_Undeclared
+ || r->isDependentContext()))
+ {
return true;
}
@@ -81,6 +81,9 @@ bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) {
compiler.getSourceManager().getSpellingLoc(
canon->getNameInfo().getLoc()))
|| canon->isMain()
+ || (decl->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate
+ && (decl->getDescribedFunctionTemplate()->spec_begin()
+ != decl->getDescribedFunctionTemplate()->spec_end()))
|| (compiler.getDiagnostics().getDiagnosticLevel(
diag::warn_unused_function, decl->getLocation())
< DiagnosticsEngine::Warning))
@@ -102,13 +105,15 @@ bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) {
(canon->isDefined()
#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
? (canon->isExternallyVisible()
- ? "Unreferenced externally visible function definition"
- : "Unreferenced externally invisible function definition")
+ ? "Unreferenced externally visible function%0 definition"
+ : "Unreferenced externally invisible function%0 definition")
#else
- ? "Unreferenced function definition"
+ ? "Unreferenced function%0 definition"
#endif
- : "Unreferenced function declaration"),
+ : "Unreferenced function%0 declaration"),
decl->getLocation())
+ << (decl->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate
+ ? " template" : "")
<< decl->getSourceRange();
if (canon->isDefined() && !compat::isFirstDecl(*decl)) {
report(