Skip to content

[Clang] Enable -Wunused-template under -Wall - #206123

Merged
vgvassilev merged 1 commit into
llvm:mainfrom
flash1729:enable-wunused-template
Jul 6, 2026
Merged

vgvassilev merged 1 commit into
llvm:mainfrom
flash1729:enable-wunused-template

Conversation

@flash1729

@flash1729 flash1729 commented Jun 26, 2026 •

Copy link
Copy Markdown
Member

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

Needs to be reviewed

Closes #202945

cc @AaronBallman @vgvassilev

@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jun 26, 2026
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-clang

Author: Aditya Medhane (flash1729)

Changes

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:

  • #202969
  • #202971
  • #202973
  • #202974
  • #202988

Closes #202945

cc @AaronBallman @vgvassilev


Full diff: https://github.com/llvm/llvm-project/pull/206123.diff

5 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+4)
  • (modified) clang/include/clang/Basic/DiagnosticGroups.td (+1-1)
  • (modified) clang/test/Misc/warning-wall.c (+2)
  • (modified) clang/test/SemaCXX/warn-func-not-needed.cpp (+1-1)
  • (modified) clang/test/SemaCXX/warn-variable-not-needed.cpp (+1-1)
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>

@flash1729
flash1729 marked this pull request as draft June 27, 2026 15:34

@AaronBallman AaronBallman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is worth trying; hopefully it's not too disruptive.

Comment thread clang/docs/ReleaseNotes.rst Resolved
@vgvassilev
vgvassilev force-pushed the enable-wunused-template branch from 07c80e2 to 358abde Compare June 29, 2026 14:16
@github-actions

github-actions Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 120407 tests passed
  • 4930 tests skipped

✅ The build succeeded and all tests passed.

@flash1729
flash1729 force-pushed the enable-wunused-template branch 2 times, most recently from 5279947 to d747bd2 Compare July 3, 2026 16:31
@flash1729
flash1729 marked this pull request as ready for review July 3, 2026 16:36
@flash1729
flash1729 force-pushed the enable-wunused-template branch from d747bd2 to db97aa6 Compare July 3, 2026 17:43
@vgvassilev
vgvassilev force-pushed the enable-wunused-template branch from db97aa6 to d500a28 Compare July 4, 2026 05:58
@AaronBallman

Copy link
Copy Markdown
Contributor

Precommit CI found relevant failures:

   In file included from /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/asan/tests/asan_internal_interface_test.cpp:13:
  In file included from /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/asan/tests/asan_test_utils.h:22:
  /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h:77:10: error: unused function template 'Ident' [-Werror,-Wunused-template]
     77 | static T Ident(T t) {
        |          ^~~~~

   In file included from /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/sanitizer_common/tests/sanitizer_mutex_test.cpp:15:
  In file included from /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/sanitizer_common/tests/sanitizer_pthread_wrappers.h:20:
  /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h:77:10: error: unused function template 'Ident' [-Werror,-Wunused-template]
     77 | static T Ident(T t) {
        |          ^~~~~
  /home/gha/actions-runner/_work/llvm-project/llvm-project/compiler-rt/lib/sanitizer_common/tests/sanitizer_mutex_test.cpp:122:13: error: unused function template 'check_locked' [-Werror,-Wunused-template]
    122 | static void check_locked(MutexType *mtx) {
        |             ^~~~~~~~~~~~

@flash1729

Copy link
Copy Markdown
Member Author

I have opened #207706 to address the same @AaronBallman

@vgvassilev
vgvassilev force-pushed the enable-wunused-template branch from d500a28 to 06e2f2b Compare July 6, 2026 13:30
@flash1729
flash1729 force-pushed the enable-wunused-template branch from 06e2f2b to 10a8f61 Compare July 6, 2026 14:20
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.
@flash1729
flash1729 force-pushed the enable-wunused-template branch from 10a8f61 to e75341a Compare July 6, 2026 17:30
@flash1729

Copy link
Copy Markdown
Member Author

Premerge is fully green now, all the in-tree cleanups have landed.
Ready for review @vgvassilev @AaronBallman @cor3ntin @erichkeane

@vgvassilev vgvassilev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @flash1729 for the efforts you put in this. LGTM!

@erichkeane erichkeane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AaronBallman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@vgvassilev
vgvassilev merged commit f348d96 into llvm:main Jul 6, 2026
10 checks passed
@llvm-ci

llvm-ci commented Jul 6, 2026

Copy link
Copy Markdown

LLVM Buildbot has detected a new failure on builder lldb-remote-linux-ubuntu running on as-builder-9 while building clang at step 16 "test-check-lldb-api".

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
Step 16 (test-check-lldb-api) failure: Test just built components: check-lldb-api completed (failure)
******************** TEST 'lldb-api :: functionalities/thread/concurrent_events/TestConcurrentManySignals.py' FAILED ********************
Script:
--
/usr/bin/python3.12 /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin --libcxx-include-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include/c++/v1 --libcxx-include-target-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/include/aarch64-unknown-linux-gnu/c++/v1 --libcxx-library-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib/aarch64-unknown-linux-gnu --triple aarch64-unknown-linux-gnu --build-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build --lldb-module-cache-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build/module-cache-lldb/lldb-api --clang-module-cache-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build/module-cache-clang/lldb-api --executable /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin/lldb --lldb-python-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/local/lib/python3.12/dist-packages --compiler /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/clang --dsymutil /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./bin --lldb-obj-root /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/tools/lldb --lldb-libs-dir /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/./lib --cmake-build-type Release --platform-url connect://arm64-linux-04.lab.llvm.org:1234 --platform-working-dir /home/ubuntu/lldb-tests --sysroot /mnt/fs/sysroots/aarch64-linux-gnu --env ARCH_CFLAGS=-mcpu=cortex-a78 --platform-name remote-linux --skip-category=lldb-server /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/functionalities/thread/concurrent_events -p TestConcurrentManySignals.py
--
Exit Code: 1

Command Output (stdout):
--
Setting up remote platform 'remote-linux'
Connecting to remote platform 'remote-linux' at 'connect://arm64-linux-04.lab.llvm.org:1234'...
Connected.
Setting remote platform working directory to '/home/ubuntu/lldb-tests'...
Skipping the following test categories: lldb-server, libc++, msvcstl, dsym, pdb, gmodules, debugserver, objc, lldb-dap

--
Command Output (stderr):
--
WARNING:root:Custom libc++ is not supported for remote runs: ignoring --libcxx arguments
FAIL: LLDB (/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/clang-aarch64) :: test (TestConcurrentManySignals.ConcurrentManySignals.test)
Log Files:
 - /home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/lldb-test-build/functionalities/thread/concurrent_events/TestConcurrentManySignals/Failure_test.log
======================================================================
FAIL: test (TestConcurrentManySignals.ConcurrentManySignals.test)
   Test 100 signals from 100 threads.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py", line 175, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/test/API/functionalities/thread/concurrent_events/TestConcurrentManySignals.py", line 17, in test
    self.do_thread_actions(num_signal_threads=100)
  File "/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/concurrent_base.py", line 261, in do_thread_actions
    self.assertEqual(
AssertionError: 1 != 0 : Expected main thread (finish) breakpoint to be hit once
Config=aarch64-/home/buildbot/worker/as-builder-9/lldb-remote-linux-ubuntu/build/bin/clang
----------------------------------------------------------------------
Ran 1 test in 7.308s

FAILED (failures=1)

--

********************


@clementval

Copy link
Copy Markdown
Contributor

I think this patch makes the flang and flang-rt precommit CI failing.

@erichkeane

Copy link
Copy Markdown
Contributor

@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?

@erichkeane

Copy link
Copy Markdown
Contributor

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 RTNAME functions? Probalby worth a revert here, and @flash1729 and @vgvassilev could perhaps take a look to see if these are failures that we can fix reasonably enough. All are unit-tests in Flang-runtime though.

@erichkeane

Copy link
Copy Markdown
Contributor

I've set a revert to merge when CI passes: #207848

erichkeane added a commit that referenced this pull request Jul 6, 2026
Reverts #206123

See the Flang Runtime unit test failures, we probably should fix those
before merging this to keep buildbots green.
llvm-sync Bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 6, 2026
…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.
llvm-upstream-sync Bot pushed a commit to sriyalamar/cpullvm-toolchain that referenced this pull request Jul 6, 2026
…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.
llvm-upstreamsync Bot pushed a commit to qualcomm/cpullvm-toolchain that referenced this pull request Jul 6, 2026
…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.
vgvassilev pushed a commit that referenced this pull request Jul 8, 2026
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
gandhi56 pushed a commit that referenced this pull request Jul 9, 2026
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
gandhi56 pushed a commit that referenced this pull request Jul 9, 2026
Reverts #206123

See the Flang Runtime unit test failures, we probably should fix those
before merging this to keep buildbots green.
gandhi56 pushed a commit that referenced this pull request Jul 9, 2026
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
fanquake added a commit to bitcoin/bitcoin that referenced this pull request Jul 17, 2026
…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
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Jul 19, 2026
…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
sedited added a commit to bitcoin/bitcoin that referenced this pull request Aug 5, 2026
…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
@flash1729
flash1729 deleted the enable-wunused-template branch August 7, 2026 08:46
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 9, 2026
…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
sipa added a commit to bitcoin-core/minisketch that referenced this pull request Aug 14, 2026
…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
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 19, 2026
…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
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 19, 2026
…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
medismailben added a commit to medismailben/llvm-project that referenced this pull request Sep 8, 2026
`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]>
@sahu-SuMiT

Copy link
Copy Markdown

Awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable -Wunused-template by default (add to -Wall)

8 participants