Repository navigation
[Clang] Enable -Wunused-template under -Wall - #206123
Conversation
|
@llvm/pr-subscribers-clang Author: Aditya Medhane (flash1729) ChangesUncomment
Depends onThe in-tree occurrences were cleaned up first in a series of NFC PRs tracked by #202945. This change only builds clean once those land, so CI will be red on any area whose cleanup is not yet merged. Remaining prerequisites:
Closes #202945 cc @AaronBallman @vgvassilev 5 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d1303d4c98507..a4c1381836d75 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -676,6 +676,10 @@ Improvements to Clang's diagnostics
- Diagnostics for the C++11 range-based for statement now report the correct
iterator type in notes for invalid iterator types.
+- ``-Wunused-template`` is now part of ``-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)
+
Improvements to Clang's time-trace
----------------------------------
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 6418ab4757a0c..17f4629c1c4c4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1359,7 +1359,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,
diff --git a/clang/test/Misc/warning-wall.c b/clang/test/Misc/warning-wall.c
index 6d6c4e562400f..ade9cbaace77e 100644
--- a/clang/test/Misc/warning-wall.c
+++ b/clang/test/Misc/warning-wall.c
@@ -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
diff --git a/clang/test/SemaCXX/warn-func-not-needed.cpp b/clang/test/SemaCXX/warn-func-not-needed.cpp
index cb3cae4cd6c76..74438543c43b7 100644
--- a/clang/test/SemaCXX/warn-func-not-needed.cpp
+++ b/clang/test/SemaCXX/warn-func-not-needed.cpp
@@ -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() {
diff --git a/clang/test/SemaCXX/warn-variable-not-needed.cpp b/clang/test/SemaCXX/warn-variable-not-needed.cpp
index 272c8998d15c0..d234e9140e3fd 100644
--- a/clang/test/SemaCXX/warn-variable-not-needed.cpp
+++ b/clang/test/SemaCXX/warn-variable-not-needed.cpp
@@ -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>
|
AaronBallman
left a comment
There was a problem hiding this comment.
I think this is worth trying; hopefully it's not too disruptive.
07c80e2 to
358abde
Compare
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
5279947 to
d747bd2
Compare
d747bd2 to
db97aa6
Compare
db97aa6 to
d500a28
Compare
|
Precommit CI found relevant failures: |
|
I have opened #207706 to address the same @AaronBallman |
d500a28 to
06e2f2b
Compare
06e2f2b to
10a8f61
Compare
Uncomment UnusedTemplate in the Unused diagnostic group so -Wunused-template is part of -Wall. It diagnoses unused function and variable templates with internal linkage; in a header, such a template gives every translation unit its own internal-linkage copy, which is a latent ODR violation. Also update the affected tests (Misc/warning-wall.c and the warn-func-not-needed.cpp / warn-variable-not-needed.cpp -verify tests) and add a release note. Closes llvm#202945.
10a8f61 to
e75341a
Compare
|
Premerge is fully green now, all the in-tree cleanups have landed. |
vgvassilev
left a comment
There was a problem hiding this comment.
Thank you @flash1729 for the efforts you put in this. LGTM!
erichkeane
left a comment
There was a problem hiding this comment.
I think I'm ok with this, we should make sure it is CLEAR to folks that they can disable this with -Wno-unused-template (so they don't have to throw out all of -Wunused if they want to suppress just this), so hopefully the Release Notes are sufficient here. I suspect we'll get quite a few angry folks about this one though :D
AaronBallman
left a comment
There was a problem hiding this comment.
LGTM, let's pay attention to fall-out from the changes though, particularly once the release candidate goes out in a week or two. Hopefully it's not too disruptive!
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/195/builds/27391 Here is the relevant piece of the build log for the reference |
|
I think this patch makes the flang and flang-rt precommit CI failing. |
|
@flash1729 : Do you perhaps have cycles to fix the FLANG build too? @clementval : Can you share a link to the buildbot you think this causes failures for? |
|
Hmm.. I DO see at least a couple of those that might be false positives, unless I'm missing something that is happening in the time-intrinsic.cpp |
|
I've set a revert to merge when CI passes: #207848 |
Reverts #206123 See the Flang Runtime unit test failures, we probably should fix those before merging this to keep buildbots green.
…7848) Reverts llvm/llvm-project#206123 See the Flang Runtime unit test failures, we probably should fix those before merging this to keep buildbots green.
…7848) Reverts llvm/llvm-project#206123 See the Flang Runtime unit test failures, we probably should fix those before merging this to keep buildbots green.
…7848) Reverts llvm/llvm-project#206123 See the Flang Runtime unit test failures, we probably should fix those before merging this to keep buildbots green.
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
Uncomment `UnusedTemplate` in the `Unused` diagnostic group so `-Wunused-template` becomes part of `-Wall`. `-Wunused-template` flags unused function and variable templates with internal linkage. In a header, such a template gives every translation unit its own internal-linkage copy, which is a latent ODR violation (ill-formed, no diagnostic required), so enabling this surfaces a real class of bugs and keeps the pattern from reappearing. ### Depends on The in-tree occurrences were cleaned up first in a series of NFC PRs tracked by #202945. This change only builds clean once those land, so CI will be red on any area whose cleanup is not yet merged. Remaining prerequisites: Approved - #202969 - #202971 - #202973 - #202974 - #206309 - #206312 Needs to be reviewed - #202988 - #206308 Closes #202945 cc @AaronBallman @vgvassilev
Reverts #206123 See the Flang Runtime unit test failures, we probably should fix those before merging this to keep buildbots green.
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
…s overload afab8d4 fuzz, refactor: Remove `Serialize` overload (Hennadii Stepanov) efa7f8c fuzz: Remove unused `DeserializeFromFuzzingInput` params overload (Hennadii Stepanov) Pull request description: Clang recently enabled `-Wunused-template` under `-Wall` (see llvm/llvm-project#206123, llvm/llvm-project#207848, llvm/llvm-project#208001). Our codebase [triggers](https://my.cdash.org/builds/3714664/build) some of these warnings. This PR handles the simplest case, where the unused template function can simply be removed. Other cases need different approaches, as their usage depends on the actual TU they are compiled in. Those are left for follow-ups. While cleaning up `src/test/fuzz/deserialize.cpp`, another [suggestion](#35679 (comment)) has been addressed. ACKs for top commit: maflcko: lgtm ACK afab8d4 brunoerg: reACK afab8d4 frankomosh: Review ACK afab8d4 Tree-SHA512: 60e98034aa642a8bc0e43dd6c02e60927b5b51be21bbef5812569c797f5d80a04011bced43a34e237e454008382c792a8f7adbde960268f6ae2c0fe3bb2749b7
…ingInput` params overload 9828a26 fuzz, refactor: Remove `Serialize` overload (Hennadii Stepanov) 0804346 fuzz: Remove unused `DeserializeFromFuzzingInput` params overload (Hennadii Stepanov) Pull request description: Clang recently enabled `-Wunused-template` under `-Wall` (see llvm/llvm-project#206123, llvm/llvm-project#207848, llvm/llvm-project#208001). Our codebase [triggers](https://my.cdash.org/builds/3714664/build) some of these warnings. This PR handles the simplest case, where the unused template function can simply be removed. Other cases need different approaches, as their usage depends on the actual TU they are compiled in. Those are left for follow-ups. While cleaning up `src/test/fuzz/deserialize.cpp`, another [suggestion](bitcoin/bitcoin#35679 (comment)) has been addressed. ACKs for top commit: maflcko: lgtm ACK 9828a26 brunoerg: reACK 9828a26 frankomosh: Review ACK 9828a26 Tree-SHA512: 60e98034aa642a8bc0e43dd6c02e60927b5b51be21bbef5812569c797f5d80a04011bced43a34e237e454008382c792a8f7adbde960268f6ae2c0fe3bb2749b7
…nearize namespace 21b4b79 test: Move cluster_linearize.h contents into cluster_linearize namespace (Hennadii Stepanov) Pull request description: Clang recently enabled `-Wunused-template` under `-Wall` (see llvm/llvm-project#206123, llvm/llvm-project#207848, llvm/llvm-project#208001). Our codebase [triggers](https://my.cdash.org/builds/3714664/build) some of these warnings. This PR: 1. Avoids Clang's `-Wunused-template` warnings in `src/test/util/cluster_linearize.h` when building the `bench_bitcoin` and `fuzz` targets. 2. Follows the C++ Core Guidelines: "[SF.21: Don't use an unnamed (anonymous) namespace in a header](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf21-dont-use-an-unnamed-anonymous-namespace-in-a-header)". 3. Drops `[[maybe_unused]]` annotations, which are no longer needed after changing the linkage from internal to external. Along with #35679, this resolves all instances of this warning in the test/bench/fuzz code. Another related change: bitcoin-core/minisketch#102. --- Steps to reproduce on the master branch @ 70d9ec7: ```console $ CXXFLAGS="-Wunused-template" cmake -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBUILD_BENCH=ON $ cmake --build build -t test_bitcoin $ cmake --build build -t bench_bitcoin [19/62] Building CXX object src/bench/CMakeFiles/bench_bitcoin.dir/cluster_linearize.cpp.o In file included from /home/hebasto/dev/bitcoin/src/bench/cluster_linearize.cpp:9: /home/hebasto/dev/bitcoin/src/test/util/cluster_linearize.h:122:17: warning: unused function template 'Ser' [-Wunused-template] 122 | static void Ser(Stream& s, const DepGraph<SetType>& depgraph) | ^~~ /home/hebasto/dev/bitcoin/src/test/util/cluster_linearize.h:286:6: warning: unused function template 'SanityCheck' [-Wunused-template] 286 | void SanityCheck(const DepGraph<SetType>& depgraph) | ^~~~~~~~~~~ /home/hebasto/dev/bitcoin/src/test/util/cluster_linearize.h:383:6: warning: unused function template 'SanityCheck' [-Wunused-template] 383 | void SanityCheck(const DepGraph<SetType>& depgraph, std::span<const DepGraphIndex> linearization) | ^~~~~~~~~~~ 3 warnings generated. [62/62] Linking CXX executable bin/bench_bitcoin ``` ACKs for top commit: maflcko: lgtm ACK 21b4b79 sedited: ACK 21b4b79 Tree-SHA512: 893082c2dc3295b68738c438094656b3568f85b95e0e2f9b0b9dd178d0613e4cb50cd2300a9595e390b9d0a4c650ca78d2772dd1010c178756cefbeef6e2ed94
…into cluster_linearize namespace 0982505 test: Move cluster_linearize.h contents into cluster_linearize namespace (Hennadii Stepanov) Pull request description: Clang recently enabled `-Wunused-template` under `-Wall` (see llvm/llvm-project#206123, llvm/llvm-project#207848, llvm/llvm-project#208001). Our codebase [triggers](https://my.cdash.org/builds/3714664/build) some of these warnings. This PR: 1. Avoids Clang's `-Wunused-template` warnings in `src/test/util/cluster_linearize.h` when building the `bench_bitcoin` and `fuzz` targets. 2. Follows the C++ Core Guidelines: "[SF.21: Don't use an unnamed (anonymous) namespace in a header](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf21-dont-use-an-unnamed-anonymous-namespace-in-a-header)". 3. Drops `[[maybe_unused]]` annotations, which are no longer needed after changing the linkage from internal to external. Along with bitcoin/bitcoin#35679, this resolves all instances of this warning in the test/bench/fuzz code. Another related change: bitcoin-core/minisketch#102. --- Steps to reproduce on the master branch @ c7bd54a: ```console $ CXXFLAGS="-Wunused-template" cmake -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBUILD_BENCH=ON $ cmake --build build -t test_bitcoin $ cmake --build build -t bench_bitcoin [19/62] Building CXX object src/bench/CMakeFiles/bench_bitcoin.dir/cluster_linearize.cpp.o In file included from /home/hebasto/dev/bitcoin/src/bench/cluster_linearize.cpp:9: /home/hebasto/dev/bitcoin/src/test/util/cluster_linearize.h:122:17: warning: unused function template 'Ser' [-Wunused-template] 122 | static void Ser(Stream& s, const DepGraph<SetType>& depgraph) | ^~~ /home/hebasto/dev/bitcoin/src/test/util/cluster_linearize.h:286:6: warning: unused function template 'SanityCheck' [-Wunused-template] 286 | void SanityCheck(const DepGraph<SetType>& depgraph) | ^~~~~~~~~~~ /home/hebasto/dev/bitcoin/src/test/util/cluster_linearize.h:383:6: warning: unused function template 'SanityCheck' [-Wunused-template] 383 | void SanityCheck(const DepGraph<SetType>& depgraph, std::span<const DepGraphIndex> linearization) | ^~~~~~~~~~~ 3 warnings generated. [62/62] Linking CXX executable bin/bench_bitcoin ``` ACKs for top commit: maflcko: lgtm ACK 0982505 sedited: ACK 0982505 Tree-SHA512: 893082c2dc3295b68738c438094656b3568f85b95e0e2f9b0b9dd178d0613e4cb50cd2300a9595e390b9d0a4c650ca78d2772dd1010c178756cefbeef6e2ed94
…selections d14cd49 Avoid Clang's `-Wunused-template` under restricted field selections (Hennadii Stepanov) Pull request description: Clang recently enabled `-Wunused-template` under `-Wall` (see llvm/llvm-project#206123, llvm/llvm-project#207848, llvm/llvm-project#208001), which [breaks](https://my.cdash.org/builds/3714664/build) `-Wall -Werror` builds of downstream projects that compile minisketch with a restricted field set, including Bitcoin Core. On the master branch @ d1bd01e: ```console $ CXXFLAGS="-Wunused-template" cmake -B build -DCMAKE_CXX_COMPILER=clang++ -DMINISKETCH_FIELDS=2 $ cmake --build build [35/40] Building CXX object src/CMakeFiles/minisketch.dir/fields/clmul_1byte.cpp.o In file included from /home/hebasto/dev/minisketch/src/fields/clmul_1byte.cpp:12: /home/hebasto/dev/minisketch/src/fields/clmul_common_impl.h:31:60: warning: unused function template 'MulWithClMulReduce' [-Wunused-template] 31 | template<typename I, int BITS, I MOD> NO_SANITIZE_MEMORY I MulWithClMulReduce(I a, I b) | ^~~~~~~~~~~~~~~~~~ 1 warning generated. [37/40] Building CXX object src/CMakeFiles/minisketch_verify.dir/fields/clmul_1byte.cpp.o In file included from /home/hebasto/dev/minisketch/src/fields/clmul_1byte.cpp:12: /home/hebasto/dev/minisketch/src/fields/clmul_common_impl.h:31:60: warning: unused function template 'MulWithClMulReduce' [-Wunused-template] 31 | template<typename I, int BITS, I MOD> NO_SANITIZE_MEMORY I MulWithClMulReduce(I a, I b) | ^~~~~~~~~~~~~~~~~~ 1 warning generated. [40/40] Linking CXX executable bin/test-verify ``` Bitcoin Core's case: ```console $ CXXFLAGS="-Wunused-template" cmake -B build -DCMAKE_CXX_COMPILER=clang++ -DMINISKETCH_FIELDS=32 $ cmake --build build [16/40] Building CXX object src/CMakeFiles/minisketch.dir/fields/clmul_4bytes.cpp.o In file included from /home/hebasto/dev/minisketch/src/fields/clmul_4bytes.cpp:12: /home/hebasto/dev/minisketch/src/fields/clmul_common_impl.h:68:62: warning: unused function template 'MulTrinomial' [-Wunused-template] 68 | template<typename I, int BITS, int POS> NO_SANITIZE_MEMORY I MulTrinomial(I a, I b) | ^~~~~~~~~~~~ 1 warning generated. [36/40] Building CXX object src/CMakeFiles/minisketch_verify.dir/fields/clmul_4bytes.cpp.o In file included from /home/hebasto/dev/minisketch/src/fields/clmul_4bytes.cpp:12: /home/hebasto/dev/minisketch/src/fields/clmul_common_impl.h:68:62: warning: unused function template 'MulTrinomial' [-Wunused-template] 68 | template<typename I, int BITS, int POS> NO_SANITIZE_MEMORY I MulTrinomial(I a, I b) | ^~~~~~~~~~~~ 1 warning generated. [40/40] Linking CXX executable bin/test-verify ``` --- Alternatively, ~function templates can be moved out of the anonymous namespace~ the anonymous namespace can be switched to a named one (C++ Core Guidelines, [SF.21](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf21-dont-use-an-unnamed-anonymous-namespace-in-a-header)). ACKs for top commit: sipa: ACK d14cd49 Tree-SHA512: 2aec8cc492e8f434020be61f47adbc2ef53547b245667f064e2b8d59d0375cc9bb27c8a690a6450010d3164ecacdcb3c37b479f806441ada633d997a1bc7d884
…ingInput` params overload afab8d4225c720f8d8658d4ea134505b3d9531f9 fuzz, refactor: Remove `Serialize` overload (Hennadii Stepanov) efa7f8c1437681dfae536017da6f27c75f8f2309 fuzz: Remove unused `DeserializeFromFuzzingInput` params overload (Hennadii Stepanov) Pull request description: Clang recently enabled `-Wunused-template` under `-Wall` (see llvm/llvm-project#206123, llvm/llvm-project#207848, llvm/llvm-project#208001). Our codebase [triggers](https://my.cdash.org/builds/3714664/build) some of these warnings. This PR handles the simplest case, where the unused template function can simply be removed. Other cases need different approaches, as their usage depends on the actual TU they are compiled in. Those are left for follow-ups. While cleaning up `src/test/fuzz/deserialize.cpp`, another [suggestion](bitcoin/bitcoin#35679 (comment)) has been addressed. ACKs for top commit: maflcko: lgtm ACK afab8d4225c720f8d8658d4ea134505b3d9531f9 brunoerg: reACK afab8d4225c720f8d8658d4ea134505b3d9531f9 frankomosh: Review ACK afab8d4225c720f8d8658d4ea134505b3d9531f9 Tree-SHA512: 60e98034aa642a8bc0e43dd6c02e60927b5b51be21bbef5812569c797f5d80a04011bced43a34e237e454008382c792a8f7adbde960268f6ae2c0fe3bb2749b7
…into cluster_linearize namespace 21b4b790e4884e1edef6ea8da589e71f1ceacde8 test: Move cluster_linearize.h contents into cluster_linearize namespace (Hennadii Stepanov) Pull request description: Clang recently enabled `-Wunused-template` under `-Wall` (see llvm/llvm-project#206123, llvm/llvm-project#207848, llvm/llvm-project#208001). Our codebase [triggers](https://my.cdash.org/builds/3714664/build) some of these warnings. This PR: 1. Avoids Clang's `-Wunused-template` warnings in `src/test/util/cluster_linearize.h` when building the `bench_bitcoin` and `fuzz` targets. 2. Follows the C++ Core Guidelines: "[SF.21: Don't use an unnamed (anonymous) namespace in a header](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf21-dont-use-an-unnamed-anonymous-namespace-in-a-header)". 3. Drops `[[maybe_unused]]` annotations, which are no longer needed after changing the linkage from internal to external. Along with bitcoin/bitcoin#35679, this resolves all instances of this warning in the test/bench/fuzz code. Another related change: bitcoin-core/minisketch#102. --- Steps to reproduce on the master branch @ 70d9ec7f3d452789d04dce81dc02db0b3b778bb5: ```console $ CXXFLAGS="-Wunused-template" cmake -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBUILD_BENCH=ON $ cmake --build build -t test_bitcoin $ cmake --build build -t bench_bitcoin [19/62] Building CXX object src/bench/CMakeFiles/bench_bitcoin.dir/cluster_linearize.cpp.o In file included from /home/hebasto/dev/bitcoin/src/bench/cluster_linearize.cpp:9: /home/hebasto/dev/bitcoin/src/test/util/cluster_linearize.h:122:17: warning: unused function template 'Ser' [-Wunused-template] 122 | static void Ser(Stream& s, const DepGraph<SetType>& depgraph) | ^~~ /home/hebasto/dev/bitcoin/src/test/util/cluster_linearize.h:286:6: warning: unused function template 'SanityCheck' [-Wunused-template] 286 | void SanityCheck(const DepGraph<SetType>& depgraph) | ^~~~~~~~~~~ /home/hebasto/dev/bitcoin/src/test/util/cluster_linearize.h:383:6: warning: unused function template 'SanityCheck' [-Wunused-template] 383 | void SanityCheck(const DepGraph<SetType>& depgraph, std::span<const DepGraphIndex> linearization) | ^~~~~~~~~~~ 3 warnings generated. [62/62] Linking CXX executable bin/bench_bitcoin ``` ACKs for top commit: maflcko: lgtm ACK 21b4b790e4884e1edef6ea8da589e71f1ceacde8 sedited: ACK 21b4b790e4884e1edef6ea8da589e71f1ceacde8 Tree-SHA512: 893082c2dc3295b68738c438094656b3568f85b95e0e2f9b0b9dd178d0613e4cb50cd2300a9595e390b9d0a4c650ca78d2772dd1010c178756cefbeef6e2ed94
`static` on a namespace-scope function template gives every instantiation internal linkage, so each translation unit including TestingSupport/TestUtilities.h gets its own copy and -Wunused-template fires in any of them that never calls roundtripJSON. That is 52 of the 57 unit test files which include the header: lldb/unittests/TestingSupport/TestUtilities.h:68:48: error: unused function template 'roundtripJSON' [-Werror,-Wunused-template] 1529d35, the reland of llvm#206123, added -Wunused-template to -Wall, which makes this a hard error under -Werror. That change is currently reverted on main by 8710728, so a compiler built from main today does not surface it. It did ship in clang 23.1.0 though, because the revert landed too late to make that tag and only reached the release branch in 23.1.1, so building LLDB with a released 23.1.0 compiler hits this now. Function templates already have vague linkage, so `static` bought nothing here and only narrowed it. Drop it, matching da69184 and 1376072 in MLIR. Signed-off-by: Med Ismail Bennani <[email protected]>
|
Awesome |
Uncomment
UnusedTemplatein theUnuseddiagnostic group so-Wunused-templatebecomes part of-Wall.-Wunused-templateflags unused function and variable templates with internal linkage. In a header, such a template gives every translation unit its own internal-linkage copy, which is a latent ODR violation (ill-formed, no diagnostic required), so enabling this surfaces a real class of bugs and keeps the pattern from reappearing.Depends on
The in-tree occurrences were cleaned up first in a series of NFC PRs tracked by #202945. This change only builds clean once those land, so CI will be red on any area whose cleanup is not yet merged. Remaining prerequisites:
Approved
Needs to be reviewed
Closes #202945
cc @AaronBallman @vgvassilev