Skip to content

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

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

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

Conversation

@flash1729

Copy link
Copy Markdown
Member

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

What has changed since:

Marked as draft until #207979 and #207983 land.

Closes #202945

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.
@vgvassilev
vgvassilev force-pushed the reland-wunused-template branch from b1e32ab to 168204d Compare July 8, 2026 14:01
@flash1729
flash1729 marked this pull request as ready for review July 8, 2026 14:05
@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 Jul 8, 2026
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-clang

Author: Aditya Medhane (flash1729)

Changes

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


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

5 Files Affected:

  • (modified) clang/docs/ReleaseNotes.md (+5)
  • (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.md b/clang/docs/ReleaseNotes.md
index 5de8e546b7812..b49a9db3d5fca 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -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
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 16ee72c80dbc8..d353a86f228ba 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -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,
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

Copy link
Copy Markdown
Member Author

ping for review @AaronBallman @erichkeane @vgvassilev

@vgvassilev
vgvassilev merged commit 1529d35 into llvm:main Jul 8, 2026
14 checks passed
ronlieb added a commit to ROCm/llvm-project that referenced this pull request Jul 9, 2026
…08001)"

[hipDNN] /__w/llvm-project/llvm-project/rocm-libraries/projects/hipdnn/data_sdk/include/hipdnn_data_sdk/utilities/ShapeUtilities.hpp:348:13:
 error: unused function template 'iterateAlongDimensions' [-Werror,-Wunused-template]

This reverts commit 1529d35.
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
@mstorsjo

mstorsjo commented Jul 9, 2026

Copy link
Copy Markdown
Member

This change breaks building Harfbuzz.

Harfbuzz internally enables a bunch of diagnostics as errors, see https://github.com/harfbuzz/harfbuzz/blob/14.2.1/src/hb.hh#L93.

Previously there were no warnings at all, but now this triggers a bunch of errors:

[1/242] Compiling C++ object src/libharfbuzz.so.0.61421.0.p/hb-common.cc.o
FAILED: src/libharfbuzz.so.0.61421.0.p/hb-common.cc.o 
clang++ -Isrc/libharfbuzz.so.0.61421.0.p -Isrc -I../src -I. -I.. -I/usr/include/freetype2 -I/usr/include/libpng16 -fdiagnostics-color=always -D_GLIBCXX_ASSERTIONS=1 -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -fno-exceptions -std=c++11 -O2 -g -fno-exceptions -fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -DHAVE_CONFIG_H -fPIC -pthread -MD -MQ src/libharfbuzz.so.0.61421.0.p/hb-common.cc.o -MF src/libharfbuzz.so.0.61421.0.p/hb-common.cc.o.d -o src/libharfbuzz.so.0.61421.0.p/hb-common.cc.o -c ../src/hb-common.cc
In file included from ../src/hb-common.cc:29:
In file included from ../src/hb.hh:561:
../src/hb-meta.hh:131:3: error: unused function template 'operator()' [-Werror,-Wunused-template]
  131 |   operator () (T&& v) const HB_AUTO_RETURN (std::forward<T> (v))
      |   ^~~~~~~~

To reproduce, clone https://github.com/harfbuzz/harfbuzz, and configure and build it like this:

$ git clone https://github.com/harfbuzz/harfbuzz
$ cd harfbuzz
$ mkdir build
$ cd build
$ CC=clang CXX=clang++ meson setup ..
$ ninja
[hit error]

@vgvassilev

Copy link
Copy Markdown
Contributor

I’d think the diagnostic is valid here. If that’s unused we can either delete that code of mark it with the maybe_unused attribute.

@mstorsjo

mstorsjo commented Jul 9, 2026

Copy link
Copy Markdown
Member

I filed harfbuzz/harfbuzz#6059 upstream so they can figure out what they want to do about it - I just happened to run into this while building harfbuzz as part of VLC.

@Thyre

Thyre commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

If I saw correctly, it looks like offload fails to build in pull requests with this change being re-landed. Failing CI runs include e.g.:

Errors include e.g.:

2026-07-08T22:43:55.4409871Z /home/gha/actions-runner/_work/llvm-project/llvm-project/offload/plugins-nextgen/amdgpu/src/rtl.cpp:129:21: error: unused function template 'iterate' [-Werror,-Wunused-template]
2026-07-08T22:43:55.4410701Z   129 | static hsa_status_t iterate(IterFuncTy Func, IterFuncArgTy FuncArg,
2026-07-08T22:43:55.4411080Z       |                     ^~~~~~~
2026-07-08T22:43:55.4411328Z 1 error generated.
[...]
2026-07-08T22:43:55.6791199Z In file included from /home/gha/actions-runner/_work/llvm-project/llvm-project/offload/liboffload/src/OffloadImpl.cpp:14:
2026-07-08T22:43:55.6791997Z In file included from /home/gha/actions-runner/_work/llvm-project/llvm-project/offload/liboffload/include/OffloadImpl.hpp:10:
2026-07-08T22:43:55.6793090Z /home/gha/actions-runner/_work/llvm-project/llvm-project/offload/liboffload/../plugins-nextgen/common/include/PluginInterface.h:101:14: error: unused function template 'check' [-Werror,-Wunused-template]
2026-07-08T22:43:55.6794035Z   101 | static Error check(int32_t ErrorCode, const char *ErrFmt, ArgsTy... Args);
2026-07-08T22:43:55.6794421Z       |              ^~~~~
2026-07-08T22:43:55.6794646Z 1 error generated.
[...]
2026-07-08T22:43:58.9306604Z In file included from /home/gha/actions-runner/_work/llvm-project/llvm-project/offload/plugins-nextgen/common/src/JIT.cpp:16:
2026-07-08T22:43:58.9307673Z /home/gha/actions-runner/_work/llvm-project/llvm-project/offload/plugins-nextgen/common/include/PluginInterface.h:101:14: error: unused function template 'check' [-Werror,-Wunused-template]
2026-07-08T22:43:58.9308623Z   101 | static Error check(int32_t ErrorCode, const char *ErrFmt, ArgsTy... Args);
2026-07-08T22:43:58.9309009Z       |              ^~~~~
2026-07-08T22:43:58.9309239Z 1 error generated.


2026-07-09T13:01:49.3420368Z /home/gha/actions-runner/_work/llvm-project/llvm-project/offload/plugins-nextgen/common/include/OffloadError.h:52:20: error: unused function template 'createOffloadError' [-Werror,-Wunused-template]
2026-07-09T13:01:49.3421724Z    52 | static llvm::Error createOffloadError(error::ErrorCode Code, const char *ErrFmt,
2026-07-09T13:01:49.3422610Z       |                    ^~~~~~~~~~~~~~~~~~
2026-07-09T13:01:49.3422966Z 1 error generated.

@flash1729

Copy link
Copy Markdown
Member Author

thanks for flagging @Thyre, this breakage is similar to past occurrences, I am working on a fix and will ship the patch soon

@behdad

behdad commented Jul 9, 2026

Copy link
Copy Markdown

I'll go ahead and ignore this in HarfBuzz. I find this warning / error unwarranted. Our types and function objects can expose methods that are currently unused by the codebase...

@vgvassilev

Copy link
Copy Markdown
Contributor

I'll go ahead and ignore this in HarfBuzz. I find this warning / error unwarranted. Our types and function objects can expose methods that are currently unused by the codebase...

In that case you can annotate those with [[maybe_unused]]. That would give you probably a good overview of the actually unused templates.

@behdad

behdad commented Jul 9, 2026

Copy link
Copy Markdown

I'll go ahead and ignore this in HarfBuzz. I find this warning / error unwarranted. Our types and function objects can expose methods that are currently unused by the codebase...

In that case you can annotate those with [[maybe_unused]]. That would give you probably a good overview of the actually unused templates.

Right. But that can really be anything. The case reported in the HB issue is of a function-object called hb_deref(). It has six overloads for operator () to handle a variety of situations. Any of those can in theory be unused.

This just makes writing encapsulated types harder.

@vgvassilev

Copy link
Copy Markdown
Contributor

I'll go ahead and ignore this in HarfBuzz. I find this warning / error unwarranted. Our types and function objects can expose methods that are currently unused by the codebase...

In that case you can annotate those with [[maybe_unused]]. That would give you probably a good overview of the actually unused templates.

Right. But that can really be anything. The case reported in the HB issue is of a function-object called hb_deref(). It has six overloads for operator () to handle a variety of situations. Any of those can in theory be unused.

This just makes writing encapsulated types harder.

I'd still claim that writing 6 times the maybe_unused attribute is a good investment ;)

@jplehr

jplehr commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

I put up #208642 to add [[maybe_unused]] in offload

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
AnthonyLatsis added a commit to bnbarham/swift that referenced this pull request Aug 3, 2026
…-Wall" (#208001)"

```
/Users/alatsis/Desktop/rebranch/swift-2/lib/Demangling/Remangler.cpp:236:15: error: unused function template 'mangleIdentifier' [-Werror,-Wunused-template]
  236 |   friend void mangleIdentifier(Mangler &M, StringRef ident);
      |               ^~~~~~~~~~~~~~~~
```

The referenced commit moves `-Wunused-template` into the `-Wunused`
group, so `-Wall` (and thus `-Werror=unused`) now flags unused
internal-linkage function/variable templates. Fixes, matching the
warning's intent (internal-linkage templates are a latent ODR hazard):
drop the redundant unqualified `mangleIdentifier` friend template (the
real one is already befriended as `Mangle::mangleIdentifier`); give the
genuinely header/file-scope helpers `TypeLookupErrorImpl`,
`assignUnlessEqual`, `tuple_allocateBuffer` and `pointer_function_cast`
external linkage via `inline`; and mark the unused variadic
`getExtraAllocationSize` cache-entry members `[[maybe_unused]]`.

See llvm/llvm-project@1529d35 (llvm/llvm-project#208001).

Assisted-by: Claude Code
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this pull request Aug 6, 2026
…-Wall" (#208001)"

```
/Users/alatsis/Desktop/rebranch/swift-2/lib/Demangling/Remangler.cpp:236:15: error: unused function template 'mangleIdentifier' [-Werror,-Wunused-template]
  236 |   friend void mangleIdentifier(Mangler &M, StringRef ident);
      |               ^~~~~~~~~~~~~~~~
```

The referenced commit moves `-Wunused-template` into the `-Wunused`
group, so `-Wall` (and thus `-Werror=unused`) now flags unused
internal-linkage function/variable templates. Fixes, matching the
warning's intent (internal-linkage templates are a latent ODR hazard):
drop the redundant unqualified `mangleIdentifier` friend template (the
real one is already befriended as `Mangle::mangleIdentifier`); give the
genuinely header/file-scope helpers `TypeLookupErrorImpl`,
`assignUnlessEqual`, `tuple_allocateBuffer` and `pointer_function_cast`
external linkage via `inline`; and mark the unused variadic
`getExtraAllocationSize` cache-entry members `[[maybe_unused]]`.

See llvm/llvm-project@1529d35 (llvm/llvm-project#208001).

Assisted-by: Claude Code
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this pull request Aug 6, 2026
…-Wall" (#208001)"

```
/Users/alatsis/Desktop/rebranch/swift-2/lib/Demangling/Remangler.cpp:236:15: error: unused function template 'mangleIdentifier' [-Werror,-Wunused-template]
  236 |   friend void mangleIdentifier(Mangler &M, StringRef ident);
      |               ^~~~~~~~~~~~~~~~
```

The referenced commit moves `-Wunused-template` into the `-Wunused`
group, so `-Wall` (and thus `-Werror=unused`) now flags unused
internal-linkage function/variable templates. Fixes, matching the
warning's intent (internal-linkage templates are a latent ODR hazard):
drop the redundant unqualified `mangleIdentifier` friend template (the
real one is already befriended as `Mangle::mangleIdentifier`); give the
genuinely header/file-scope helpers `TypeLookupErrorImpl`,
`assignUnlessEqual`, `tuple_allocateBuffer` and `pointer_function_cast`
external linkage via `inline`; and mark the unused variadic
`getExtraAllocationSize` cache-entry members `[[maybe_unused]]`.

See llvm/llvm-project@1529d35 (llvm/llvm-project#208001).

Assisted-by: Claude Code
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this pull request Aug 6, 2026
…-Wall" (#208001)"

```
/Users/alatsis/Desktop/rebranch/swift-2/lib/Demangling/Remangler.cpp:236:15: error: unused function template 'mangleIdentifier' [-Werror,-Wunused-template]
  236 |   friend void mangleIdentifier(Mangler &M, StringRef ident);
      |               ^~~~~~~~~~~~~~~~
```

The referenced commit moves `-Wunused-template` into the `-Wunused`
group, so `-Wall` (and thus `-Werror=unused`) now flags unused
internal-linkage function/variable templates. Fixes, matching the
warning's intent (internal-linkage templates are a latent ODR hazard):
drop the redundant unqualified `mangleIdentifier` friend template (the
real one is already befriended as `Mangle::mangleIdentifier`); give the
genuinely header/file-scope helpers `TypeLookupErrorImpl`,
`assignUnlessEqual`, `tuple_allocateBuffer` and `pointer_function_cast`
external linkage via `inline`; and mark the unused variadic
`getExtraAllocationSize` cache-entry members `[[maybe_unused]]`.

See llvm/llvm-project@1529d35 (llvm/llvm-project#208001).

Assisted-by: Claude Code
@flash1729
flash1729 deleted the reland-wunused-template branch August 7, 2026 08:46
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this pull request Aug 7, 2026
…-Wall" (#208001)"

```
/Users/alatsis/Desktop/rebranch/swift-2/lib/Demangling/Remangler.cpp:236:15: error: unused function template 'mangleIdentifier' [-Werror,-Wunused-template]
  236 |   friend void mangleIdentifier(Mangler &M, StringRef ident);
      |               ^~~~~~~~~~~~~~~~
```

The referenced commit moves `-Wunused-template` into the `-Wunused`
group, so `-Wall` (and thus `-Werror=unused`) now flags unused
internal-linkage function/variable templates. Fixes, matching the
warning's intent (internal-linkage templates are a latent ODR hazard):
drop the redundant unqualified `mangleIdentifier` friend template (the
real one is already befriended as `Mangle::mangleIdentifier`); give the
genuinely header/file-scope helpers `TypeLookupErrorImpl`,
`assignUnlessEqual`, `tuple_allocateBuffer` and `pointer_function_cast`
external linkage via `inline`; and mark the unused variadic
`getExtraAllocationSize` cache-entry members `[[maybe_unused]]`.

See llvm/llvm-project@1529d35 (llvm/llvm-project#208001).

Assisted-by: Claude Code
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 9, 2026
…with `[[maybe_unused]]`

9e059b2 refactor: Annotate `MakeAndPushFeature` with `[[maybe_unused]]` (Hennadii Stepanov)

Pull request description:

  This is a follow-up to bitcoin/bitcoin#35221. The `MakeAndPushFeature` member function template has no callers yet, which [triggers](https://my.cdash.org/builds/3851810/build) `-Wunused-template` now that Clang 23 [enables](llvm/llvm-project#208001) it as part of `-Wall`.

  Related PRs:
   - bitcoin/bitcoin#35679
   - bitcoin/bitcoin#35737
   - bitcoin-core/minisketch#102

ACKs for top commit:
  maflcko:
    lgtm ACK 9e059b2
  sedited:
    ACK 9e059b2

Tree-SHA512: c8b639055d34ea431d5d5f4c85815b4c19b31d6ea7e4a0c05c8420a328503028eca465fb0803eff3d4bab2c782cb8038844d3f89680928791832488494bd95d4
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
flash1729 added a commit that referenced this pull request Aug 12, 2026
…214759)

Another case of the cleanup done for #208001, which enabled
-Wunused-template under -Wall. Both helpers are `static` in
ReshapeOpsUtils.h, which reaches many TUs via Linalg.h, Tensor.h and
MemRef.h, so clang warns wherever they are not instantiated. Dropping
`static` gives them vague linkage.
flash1729 added a commit that referenced this pull request Aug 12, 2026
…es (#214756)

These are more of the cases fixed alongside #208001, which enabled
-Wunused-template under -Wall. Each template is `static` in a widely
included header, so clang warns in every TU that includes it without
instantiating it. Dropping `static` gives them vague linkage and
silences the warning.
hulxv pushed a commit that referenced this pull request Aug 12, 2026
…214759)

Another case of the cleanup done for #208001, which enabled
-Wunused-template under -Wall. Both helpers are `static` in
ReshapeOpsUtils.h, which reaches many TUs via Linalg.h, Tensor.h and
MemRef.h, so clang warns wherever they are not instantiated. Dropping
`static` gives them vague linkage.
hulxv pushed a commit that referenced this pull request Aug 12, 2026
…es (#214756)

These are more of the cases fixed alongside #208001, which enabled
-Wunused-template under -Wall. Each template is `static` in a widely
included header, so clang warns in every TU that includes it without
instantiating it. Dropping `static` gives them vague linkage and
silences the warning.
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
zhangweize9-cyber pushed a commit to zhangweize9-cyber/llvm-project that referenced this pull request Aug 16, 2026
…lvm#214759)

Another case of the cleanup done for llvm#208001, which enabled
-Wunused-template under -Wall. Both helpers are `static` in
ReshapeOpsUtils.h, which reaches many TUs via Linalg.h, Tensor.h and
MemRef.h, so clang warns wherever they are not instantiated. Dropping
`static` gives them vague linkage.
zhangweize9-cyber pushed a commit to zhangweize9-cyber/llvm-project that referenced this pull request Aug 16, 2026
…es (llvm#214756)

These are more of the cases fixed alongside llvm#208001, which enabled
-Wunused-template under -Wall. Each template is `static` in a widely
included header, so clang warns in every TU that includes it without
instantiating it. Dropping `static` gives them vague linkage and
silences the warning.
carlobertolli pushed a commit to carlobertolli/llvm-project that referenced this pull request Aug 18, 2026
…lvm#214759)

Another case of the cleanup done for llvm#208001, which enabled
-Wunused-template under -Wall. Both helpers are `static` in
ReshapeOpsUtils.h, which reaches many TUs via Linalg.h, Tensor.h and
MemRef.h, so clang warns wherever they are not instantiated. Dropping
`static` gives them vague linkage.
carlobertolli pushed a commit to carlobertolli/llvm-project that referenced this pull request Aug 18, 2026
…es (llvm#214756)

These are more of the cases fixed alongside llvm#208001, which enabled
-Wunused-template under -Wall. Each template is `static` in a widely
included header, so clang warns in every TU that includes it without
instantiating it. Dropping `static` gives them vague linkage and
silences the warning.
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
…with `[[maybe_unused]]`

0238aebf619013a761c06ad3c57a56ee50f4541c refactor: Annotate `MakeAndPushFeature` with `[[maybe_unused]]` (Hennadii Stepanov)

Pull request description:

  This is a follow-up to bitcoin/bitcoin#35221. The `MakeAndPushFeature` member function template has no callers yet, which [triggers](https://my.cdash.org/builds/3851810/build) `-Wunused-template` now that Clang 23 [enables](llvm/llvm-project#208001) it as part of `-Wall`.

  Related PRs:
   - bitcoin/bitcoin#35679
   - bitcoin/bitcoin#35737
   - bitcoin-core/minisketch#102

ACKs for top commit:
  maflcko:
    lgtm ACK 0238aebf619013a761c06ad3c57a56ee50f4541c
  sedited:
    ACK 0238aebf619013a761c06ad3c57a56ee50f4541c

Tree-SHA512: c8b639055d34ea431d5d5f4c85815b4c19b31d6ea7e4a0c05c8420a328503028eca465fb0803eff3d4bab2c782cb8038844d3f89680928791832488494bd95d4
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
ronlieb pushed a commit to ROCm/llvm-project that referenced this pull request Aug 22, 2026
Reverts `a06d76ec59bc`, restoring upstream `1529d35adbd6` ("Reland
"[Clang] Enable -Wunused-template under -Wall" (llvm#208001)").

## Why it was reverted

`a06d76ec59bc` was a same-day downstream revert on 2026-07-08 to unblock
CI. hipDNN built with `-Werror` and hit three unused internal-linkage
function templates:

```
ShapeUtilities.hpp:348:13: error: unused function template 'iterateAlongDimensions' [-Werror,-Wunused-template]
CpuFpReferenceUtilities.hpp:141:5: error: unused function template 'callFuncUnpackArgsImpl' [-Werror,-Wunused-template]
CpuFpReferenceUtilities.hpp:147:13: error: unused function template 'callFuncUnpackArgs' [-Werror,-Wunused-template]
```

Tracked as ALMIOPEN-2293.

## Why it can go back in


[ROCm/rocm-libraries#10193](ROCm/rocm-libraries#10193)
fixed all of them — nine files, the three above plus six more
`cpu_graph_executor` headers — and merged 2026-08-04 (`1aa8a6f6afa8`).

It also added the diagnostic to hipdnn's own warning flags:

```cmake
$<$<CXX_COMPILER_ID:Clang>:-Wunused-template> # Clang: catch unused internal-linkage templates (matches llvm-project CI)
```

so hipdnn enforces it independently of whether it is in `-Wall`, and
will catch regressions on its own.

The fix is reachable from TheRock's pinned `rocm-libraries` submodule
(`416eae89dcee`, 0 commits behind `1aa8a6f6afa8`), so it is present in
the tree `amd-staging` CI builds. Verified at that pin: the
`-Wunused-template` flag is on line 261 of
`projects/hipdnn/CMakeLists.txt`, and `iterateAlongDimensions` is no
longer `static`.

## Result

The four affected files now match `upstream/main` exactly (`git diff
upstream/main` over them is empty).

Note that `clang/docs/ReleaseNotes.md` already documents
`-Wunused-template` as part of `-Wunused` — a later upstream merge
restored that paragraph, so the docs and the code have been inconsistent
since the revert. This change makes them agree again.

The stale `revert_patches.txt` entry is removed.
cor3ntin added a commit that referenced this pull request Aug 25, 2026
…" (#218638)

This reverts commit 1529d35.

There are two issues:
- The change appear fairly disruptive so close to release (see comments
on #208001)
 - there are false positives (see #218429)
tru pushed a commit that referenced this pull request Aug 26, 2026
…" (#218638)

This reverts commit 1529d35.

There are two issues:
- The change appear fairly disruptive so close to release (see comments
on #208001)
 - there are false positives (see #218429)

(cherry picked from commit 8710728)
wlemkows pushed a commit to wlemkows/llvm-project that referenced this pull request Sep 4, 2026
…08001)" (llvm#218638)

This reverts commit 1529d35.

There are two issues:
- The change appear fairly disruptive so close to release (see comments
on llvm#208001)
 - there are false positives (see llvm#218429)
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)

7 participants