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

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 26 15:21:20 PDT 2017

EricWF added a comment.

In https://reviews.llvm.org/D29877#766176, @rsmith wrote:

> In https://reviews.llvm.org/D29877#765968, @EricWF wrote:
> > I think this patch still gets the following case wrong:
> >
> >   // foo.h
> >   constexpr struct {
> >     template <class T> void operator()(T) {} // emits unused template warning
> >   } foo;
> >
> What specifically do you think is wrong here? There is an unused internal linkage function template here. If we want to warn on unused internal linkage templates declared in headers, we should warn on this one.

I was confused about the linkage initially. My mistake. Should adding `inline` here change that?

> Note that any use of `foo` here from an inline function would result in ODR violations (because you get a different `foo` in each translation unit), so it's probably at least a bad idea to do that. We could suppress this warning for unused internal linkage templates declared in headers, or maybe move that to a separate warning flag; can you point us at some code that does this in practice and isn't wrong?

No. But I can point you to `range-v3` which uses this pattern and I think the idiom is somewhat appealing, but that's orthogonal to Clang diagnosing it.


More information about the cfe-commits mailing list