Skip to content

Avoid Clang's -Wunused-template under restricted field selections - #102

Merged
sipa merged 1 commit into
bitcoin-core:masterfrom
hebasto:260716-unused
Aug 14, 2026
Merged

sipa merged 1 commit into
bitcoin-core:masterfrom
hebasto:260716-unused

Conversation

@hebasto

@hebasto hebasto commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Clang recently enabled -Wunused-template under -Wall (see llvm/llvm-project#206123, llvm/llvm-project#207848, llvm/llvm-project#208001), which breaks -Wall -Werror builds of downstream projects that compile minisketch with a restricted field set, including Bitcoin Core.

On the master branch @ d1bd01e:

$ 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:

$ 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).

fanquake added a commit to bitcoin/bitcoin that referenced this pull request Aug 4, 2026
…nused]]`

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

Pull request description:

  This is a follow-up to #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:
   - #35679
   - #35737
   - bitcoin-core/minisketch#102

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

Tree-SHA512: c8b639055d34ea431d5d5f4c85815b4c19b31d6ea7e4a0c05c8420a328503028eca465fb0803eff3d4bab2c782cb8038844d3f89680928791832488494bd95d4
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
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
Comment thread src/fields/clmul_common_impl.h Resolved
Comment thread src/util.h Resolved
Clang recently enabled `-Wunused-template` under `-Wall`, which breaks
`-Wall -Werror` builds of downstream projects that compile minisketch
with a restricted field set.

@sipa sipa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ACK d14cd49

@sipa
sipa merged commit 4a179c6 into bitcoin-core:master Aug 14, 2026
5 checks passed
@hebasto
hebasto deleted the 260716-unused branch August 15, 2026 09:41
fanquake added a commit to bitcoin/bitcoin that referenced this pull request Aug 17, 2026
4a179c61e3 Merge bitcoin-core/minisketch#102: Avoid Clang's `-Wunused-template` under restricted field selections
d14cd495ff Avoid Clang's `-Wunused-template` under restricted field selections

git-subtree-dir: src/minisketch
git-subtree-split: 4a179c61e3cbe3ac2b3c027764ce8eb5183155e1
fanquake added a commit to bitcoin/bitcoin that referenced this pull request Aug 17, 2026
461e3be Squashed 'src/minisketch/' changes from d1bd01e189..4a179c61e3 (fanquake)

Pull request description:

  Includes:
  * bitcoin-core/minisketch#102

ACKs for top commit:
  hebasto:
    ACK 2dcb2c6.

Tree-SHA512: 295e217cb6d32e8d0bb4ea84bd0d6682f98735029c659ad06a6c588fa2865176d80adfca32a1a3a339ffb601e5d1cc99c81266914225e27726a8a859fee3549e
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
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 19, 2026
461e3be Squashed 'src/minisketch/' changes from d1bd01e189..4a179c61e3 (fanquake)

Pull request description:

  Includes:
  * bitcoin-core/minisketch#102

ACKs for top commit:
  hebasto:
    ACK 2dcb2c6df20bf97aef312d2d71c9ebdea66156c1.

Tree-SHA512: 295e217cb6d32e8d0bb4ea84bd0d6682f98735029c659ad06a6c588fa2865176d80adfca32a1a3a339ffb601e5d1cc99c81266914225e27726a8a859fee3549e
vmta added a commit to umkoin/umkoin that referenced this pull request Oct 8, 2026
a12f5de1c Merge bitcoin-core/minisketch#105: refactor: use inline constexpr for ID_TRANS
2ac4b7c62 refactor: use inline constexpr for ID_TRANS
4a179c61e Merge bitcoin-core/minisketch#102: Avoid Clang's `-Wunused-template` under restricted field selections
d14cd495f Avoid Clang's `-Wunused-template` under restricted field selections
d1bd01e18 Merge bitcoin-core/minisketch#98: misc: drop trailing whitespace
fe2c88a4f misc: drop trailing whitespace
f74b7e2bc Merge bitcoin-core/minisketch#75: build: Introduce CMake-based build system
850cc868d ci: Add GHA workflow with native Windows job
40d56708c doc: Add "Building with CMake" section to `README.md`
a0c86c79a build: Add CMake-based build system
ea8f66b1e Merge bitcoin-core/minisketch#89: header: Delete default Minisketch constructor
fc2495864 Merge bitcoin-core/minisketch#94: misc: trim trailing whitespace
485b16e7f misc: trim trailing whitespace
d1e6bb8bb Merge bitcoin-core/minisketch#92: doc: rename from sipa to bitcoin-core
b7b7dd0ec doc: rename from sipa to bitcoin-core
eb37a9b8e Merge bitcoin-core/minisketch#87: Avoid copy in self-assign
fe6557642 Merge bitcoin-core/minisketch#88: build: Add `-Wundef`
5cc7d2086 header: Delete default Minisketch constructor
8ea298bfa Avoid copy in self-assign
978a3d886 build: Add `-Wundef`
338704417 Merge bitcoin-core/minisketch#86: doc: fix typo in sketch_impl.h
15c2d13b6 doc: fix typo in sketch_impl.h
7be08b8a4 Merge bitcoin-core/minisketch#85: Fixes for integer precision loss
00fb4a4d8 Avoid or make integer precision conversion explicit
9d62a4d27 Avoid the need to cast/convert to size_t for vector operations
19e06cc7a Prevent overflows from large capacity/max_elements
3472e2f5e Merge bitcoin-core/minisketch#81: Avoid overflowing shift by special casing inverse of 1
653d8b2e2 Avoid overflowing shift by special casing inverse of 1
33b7c200b Merge bitcoin-core/minisketch#80: Add c++20 version of CountBits
4a48f31a3 Merge bitcoin-core/minisketch#83: ci: Fix "s390x (big-endian)" task
82b6488ac Add c++20 version of CountBits
0498084d3 ci: Fix "s390x (big-endian)" task
71709dca9 Merge bitcoin-core/minisketch#82: ci: Fix `x86_64-w64-mingw32` task
9e6127fa9 Merge bitcoin-core/minisketch#74: Avoid >> above type width in BitWriter
ed420bc17 ci: Fix `x86_64-w64-mingw32` task
fe1040f22 Drop -Wno-shift-count-overflow compile flag
154bcd43b Avoid >> above type width in BitWriter
67b87acdb Merge bitcoin-core/minisketch#78: ci: Update macOS image for CI
7de725041 ci: Update macOS image for CI
83d812ea9 Merge bitcoin-core/minisketch#73: ci: Use correct variable to designate C++ compiler
e051a7d69 ci: Install wine32 package for Windows tests
2d2c695d7 build: Drop unused `CC` variable
1810fcbd1 ci: Use correct variable to designate C++ compiler
022b95904 Merge bitcoin-core/minisketch#77: Add missing include
08443c489 Add missing include
a571ba20f Merge bitcoin-core/minisketch#68: Add missed `#include <string>`
b9a7f7e2b Merge bitcoin-core/minisketch#69: refactor: Drop unused `total` local variables
8a5af94ed Merge bitcoin-core/minisketch#70: build: Remove `-Qunused-arguments` workaround for clang + ccache
c36f1f03a Merge bitcoin-core/minisketch#72: Fix MSVC implementation of `CountBits()` function
0078bedda Ignore `HAVE_CLZ` macro when building with MSVC
1c772918c Fix MSVC implementation of `CountBits()` function
98f87c55f build: Remove `-Qunused-arguments` workaround for clang + ccache
11a1e25c8 refactor: Drop unused `total` local variables
ed6c8fcfd Add missed `#include <string>`
47f0a2d26 Merge bitcoin-core/minisketch#66: msvc: remove direct Bitcoin Core `compat.h` include
64f17584c msvc: remove Core compat.h include

git-subtree-dir: src/minisketch
git-subtree-split: a12f5de1c96e21d76f64bc647ae4f65e4fc1b636
ajtowns pushed a commit to ajtowns/bitcoin that referenced this pull request Oct 23, 2026
4a179c61e3 Merge bitcoin-core/minisketch#102: Avoid Clang's `-Wunused-template` under restricted field selections
d14cd495ff Avoid Clang's `-Wunused-template` under restricted field selections

git-subtree-dir: src/minisketch
git-subtree-split: 4a179c61e3cbe3ac2b3c027764ce8eb5183155e1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants