[PATCH] D29877: Warn about unused static file scope function template declarations.

Richard Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 13 13:56:01 PDT 2017

rsmith added inline comments.

Comment at: lib/Sema/Sema.cpp:472-477
+    // If this is a function template, we should remove if it has no
+    // specializations.
+    if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate()) {
+      if (std::distance(Template->spec_begin(), Template->spec_end()))
+        return true;
+    }
The comment doesn't match the code: you're removing function templates if they /do/ have specializations. And I think we should probably be walking the list of specializations and considering the template to be used if any specialization is used. That would affect a case like:

template<typename T> static void f() {}
template<> static void f<int>() {}

... where the primary template is still unused despite having a specialization.

Comment at: lib/Sema/Sema.cpp:492
   if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
     // If a variable usable in constant expressions is referenced,
Should we do the same thing for variable templates?

Comment at: lib/Sema/SemaDecl.cpp:1496
         return false;
+      // 'static operator' functions are defined in headers; don't warn.
+      if (FD->isOverloadedOperator() &&
Why? Defining a static operator in a header sounds like a bug to me.


More information about the cfe-commits mailing list