Skip to content

fix: unused-template warnings - #6156

Merged
rwgk merged 4 commits into
pybind:masterfrom
lucascolley:patch-2
Aug 28, 2026
Merged

fix: unused-template warnings#6156
rwgk merged 4 commits into
pybind:masterfrom
lucascolley:patch-2

Conversation

@lucascolley

@lucascolley lucascolley commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Analogous to gh-6155.

I hit the following warning when trying to build SciPy with clang-23 in scipy/scipy#26041:

In file included from /home/runner/work/scipy/scipy/.pixi/envs/build-clang-23/include/pybind11/detail/type_caster_base.h:21:
/home/runner/work/scipy/scipy/.pixi/envs/build-clang-23/include/pybind11/detail/typeid.h:61:20: error: unused function template 'type_id' [-Werror,-Wunused-template]
   61 | static std::string type_id() {
      |                    ^~~~~~~

Claude code says that this static qualifiers is incorrect, since including it on a function at namespace scope implies that the function is only visible in this translation unit.

Suggested changelog entry:

  • Fixed Clang 23 builds using -Wall -Werror by resolving -Wunused-template diagnostics and removing an unreachable type_has_shared_from_this overload exposed during the investigation.

@rwgk

rwgk commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Quick forensics:

The static keyword was present from pybind11’s very first commit:

  • Commit: 38bd711
  • Authored: July 5, 2015
  • Committed: July 9, 2015
  • Original location: include/pybind/typeid.h:33
template <typename T> static std::string type_id() {

Note: current git blame points to a 2022 clang-format commit because it split the declaration across two lines. That commit did not introduce static; history across the file’s renames confirms it was there from the root commit.

@rwgk
rwgk requested a review from henryiii as a code owner August 28, 2026 16:51
@rwgk

rwgk commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

To explain commit c531b93:

I believe Clang 18 already supports -Wunused-template.

Clang 23 merely enables it through -Wall/-Wunused by default (LLVM change).

@lucascolley

Copy link
Copy Markdown
Contributor Author

Hey @rwgk, I'm hoping to address your request for proof that this works at lucascolley/scipy#57.

You can check out that branch locally and try it yourself, with the one-liner pixi run build-clang-23 — that will build and use this branch of pybind11 from your most recent commit. The diff of that PR shows that we can remove the suppression that was added to SciPy as a workaround.

You can also see it working in CI at https://github.com/lucascolley/scipy/actions/runs/33201341348/job/98951271516?pr=57.

As for your request for info on the compiler details, you can see the entire Pixi env at https://github.com/lucascolley/scipy/actions/runs/33201341348/job/98951271516?pr=57#step:3:983.

@rwgk

rwgk commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

To explain commit 5dde98e:

While investigating the misplaced static qualifiers reported by -Wunused-template, codex found that the const void * function-template overload cannot participate in any existing call: its template parameter cannot be deduced, and no caller supplies it explicitly. When the SFINAE-constrained overload is discarded, the existing non-template ellipsis overload provides the fallback. Therefore I removed the unreachable overload instead of merely changing its linkage.

@rwgk

rwgk commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

@lucascolley I wrote the other comment before I discovered that Clang 18 already supports -Wunused-template, and that we can reproduce the errors you saw in the CI. That's all we need. If the CI passes again (I added commit 5dde98e) I'll merge.

@lucascolley lucascolley changed the title fix: remove static from type_id fix: unused-template warnings Aug 28, 2026
@lucascolley

Copy link
Copy Markdown
Contributor Author

we are 🟢!

@rwgk
rwgk merged commit f90c430 into pybind:master Aug 28, 2026
78 checks passed
@github-actions github-actions Bot added the needs changelog Possibly needs a changelog entry label Aug 28, 2026
@lucascolley
lucascolley deleted the patch-2 branch August 29, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelog Possibly needs a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants