Reland "[Clang] Enable -Wunused-template under -Wall" (#208001)

Reland of #206123, which was reverted in #207848.

What has changed since:

- flang-rt occurrences are fixed in #207979 
- openmp had one more occurrence which is fixed in #207983 
- The remaining -Wunused-template hits anywhere in CI logs are the tsan
Go runtime warnings, which are warnings only (buildgo.sh does not use
-Werror on Linux)

Marked as draft until #207979  and #207983  land.

Closes #202945
This commit is contained in:
Aditya Medhane 2026-07-08 22:17:54 +05:30 committed by GitHub
parent bdaeb7c290
commit 1529d35adb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 10 additions and 3 deletions

View file

@ -570,6 +570,11 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
allowing it to be disabled independently with `-Wno-unused-but-set-global`.
(#GH148361)
- `-Wunused-template` is now part of `-Wunused` (which is enabled by `-Wall`).
It diagnoses unused function and variable templates with internal linkage,
which in a header is a latent ODR hazard. It can be disabled with
`-Wno-unused-template`. (#GH202945)
- Added `-Wlifetime-safety` to enable lifetime safety analysis,
a CFG-based intra-procedural analysis that detects use-after-free and related
temporal safety bugs. See the

View file

@ -1368,7 +1368,7 @@ def Conversion
def Unused : DiagGroup<"unused",
[UnusedArgument, UnusedFunction, UnusedLabel,
// UnusedParameter, (matches GCC's behavior)
// UnusedTemplate, (clean-up libc++ before enabling)
UnusedTemplate,
// UnusedMemberFunction, (clean-up llvm before enabling)
UnusedPrivateField, UnusedLambdaCapture,
UnusedLocalTypedef, UnusedValue, UnusedVariable,

View file

@ -73,6 +73,8 @@ CHECK-NEXT: -Wunused-argument
CHECK-NEXT: -Wunused-function
CHECK-NEXT: -Wunneeded-internal-declaration
CHECK-NEXT: -Wunused-label
CHECK-NEXT: -Wunused-template
CHECK-NEXT: -Wunneeded-internal-declaration
CHECK-NEXT: -Wunused-private-field
CHECK-NEXT: -Wunused-lambda-capture
CHECK-NEXT: -Wunused-local-typedef

View file

@ -10,7 +10,7 @@ void foo() {
}
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}}
template <typename T>
void foo() {

View file

@ -4,7 +4,7 @@ namespace test1 {
static int abc = 42; // expected-warning {{variable 'abc' is not needed and will not be emitted}}
namespace {
template <typename T> int abc_template = 0;
template <typename T> int abc_template = 0; // expected-warning {{unused variable template}}
template <> int abc_template<int> = 0; // expected-warning {{variable 'abc_template<int>' is not needed and will not be emitted}}
} // namespace
template <typename T>