[PATCH] D143524: Make the -Wunused-template default.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 24 05:36:10 PST 2023


aaron.ballman added a comment.

In D143524#4148024 <https://reviews.llvm.org/D143524#4148024>, @v.g.vassilev wrote:

> Indeed the warning is noisy but it will potentially fix broken code which were unable to diagnose before. Especially that in some cases where static templates in header files are used as an idiom. In theory this approach can extend to cases described in https://wg21.link/p2691 where our inability to diagnose/fix these cases leads to some design decisions which may not be optimal.

We need to ensure the diagnostic is not so noisy that people disable it, though. That means a low false positive rate and a straight-forward way to silence the diagnostic on a case-by-case basis.



================
Comment at: clang/test/SemaCXX/warn-func-not-needed.cpp:13
 namespace test1_template {
-template <typename T> static void f() {}
+template <typename T> static void f() {} // expected-warning {{unused function template}}
 template <> void f<int>() {} // expected-warning {{function 'f<int>' is not needed and will not be emitted}}
----------------
v.g.vassilev wrote:
> aaron.ballman wrote:
> > Why is this unused? `f<long>()` in `foo()` should cause this to be used, right?
> > 
> > How should a user silence this diagnostic without disabling it entirely?
> Nobody uses `foo`.
Ah, good point on `foo` not being used, but the question still stands -- how does the user silence this diagnostic? It's not at all uncommon to have a primary template with specializations where the TU only uses either the primary or a specialization, but not both (and certainly not all specializations).


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143524/new/

https://reviews.llvm.org/D143524



More information about the cfe-commits mailing list