Skip to content

fix: guard cxxabi.h include with __has_include for clang-cl - #6145

Merged
rwgk merged 2 commits into
pybind:masterfrom
aidaodedjl:fix/cxxabi-has-include-guard
Aug 16, 2026
Merged

fix: guard cxxabi.h include with __has_include for clang-cl#6145
rwgk merged 2 commits into
pybind:masterfrom
aidaodedjl:fix/cxxabi-has-include-guard

Conversation

@aidaodedjl

@aidaodedjlaidaodedjl commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Description

clang-cl on Windows defines __GNUG__ but does not ship <cxxabi.h>, so detail/typeid.h fails with fatal error: 'cxxabi.h' file not found.

This introduces PYBIND11_HAS_CXXABI_H as suggested by @henryiii in #6129: defined only when <cxxabi.h> is actually available, using __has_include with a fallback for toolchains without it (pybind11 still supports C++11, where __has_include is not guaranteed). The macro guards both the #include <cxxabi.h> and the abi::__cxa_demangle call site in clean_type_id — guarding the include alone would leave the call undeclared.

Fixes#6129

Verification

Suggested changelog entry

Guard the <cxxabi.h> include with __has_include so that toolchains defining __GNUG__ without the header (e.g. clang-cl) can compile detail/typeid.h.

clang-cl on Windows defines __GNUG__ but does not ship <cxxabi.h>,
making detail/typeid.h fail to compile. Introduce PYBIND11_HAS_CXXABI_H,
defined only when <cxxabi.h> is actually available (__has_include with
a fallback for compilers without it, including C++11), and use it to
guard both the include and the abi::__cxa_demangle call site.
Fixespybind#6129
@aidaodedjl

Copy link
Copy Markdown
ContributorAuthor

The macOS PyPy job aborted in PyPy's own _pypy_generic_alias builtin (SystemError: Bad internal call!) while pytest was collecting — stack is entirely inside pluggy/PyPy, no pybind11 frames. The Ubuntu PyPy job with the same change passed, and on macOS the new macro evaluates true so clean_type_id takes the identical code path as before this change. Looks like a PyPy flake; could someone with rights re-run that job?


#if defined(__GNUG__)
# if !defined(__has_include)
# define PYBIND11_HAS_CXXABI_H

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.

Suggested change
# definePYBIND11_HAS_CXXABI_H
// All supported Clang versions provide __has_include, but GCC versions before 5 do not.
// Preserve the previous unconditional __GNUG__ behavior for those older, still-supported
// GCC versions (see PR #6145).
# definePYBIND11_HAS_CXXABI_H

This fallback is not self-explanatory and could, in principle, misidentify another GNU-compatible toolchain as providing <cxxabi.h>. I think it is important to document why preserving the old behavior is intentional for pybind11’s currently supported compiler range. It also leaves a useful hint for later: once pybind11 no longer supports GCC versions before 5, the fallback can be removed.

@aidaodedjl

aidaodedjl commented Aug 16, 2026

Copy link
Copy Markdown
ContributorAuthor

Pushed 0fee21e with the suggested comment verbatim above the fallback branch. The comment already carries the hint for later: once GCC < 5 support is dropped, the fallback branch can go too.

cpptest still passes locally (25 cases / 11285 assertions).

@rwgk
rwgk merged commit a9524c8 into pybind:masterAug 16, 2026
78 checks passed
@github-actionsgithub-actionsBot added the needs changelog Possibly needs a changelog entry label Aug 16, 2026
@henryiiihenryiii changed the title Guard cxxabi.h include with __has_include for clang-clfix: guard cxxabi.h include with __has_include for clang-clAug 18, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelogPossibly needs a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: detail\typeid.h(16,14): fatal error : 'cxxabi.h' file not found

3 participants

@aidaodedjl@rwgk@henryiii