Uh oh!
There was an error while loading. Please reload this page.
fix: guard cxxabi.h include with __has_include for clang-cl - #6145
Conversation
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
commented
Aug 16, 2026
The macOS PyPy job aborted in PyPy's own |
| #if defined(__GNUG__) | ||
| # if !defined(__has_include) | ||
| # define PYBIND11_HAS_CXXABI_H |
There was a problem hiding this comment.
| # 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.
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). |
Uh oh!
There was an error while loading. Please reload this page.
Description
clang-cl on Windows defines
__GNUG__but does not ship<cxxabi.h>, sodetail/typeid.hfails withfatal error: 'cxxabi.h' file not found.This introduces
PYBIND11_HAS_CXXABI_Has suggested by @henryiii in #6129: defined only when<cxxabi.h>is actually available, using__has_includewith a fallback for toolchains without it (pybind11 still supports C++11, where__has_includeis not guaranteed). The macro guards both the#include <cxxabi.h>and theabi::__cxa_demanglecall site inclean_type_id— guarding the include alone would leave the call undeclared.Fixes#6129
Verification
clean_type_idstill demangles (N4demo3FooE->demo::Foo) when the header is available.erase_allbranch without referencingcxxabi.hor__cxa_demangle.std::hash<std::type_index>,std::equal_to<std::type_index>everywhere **except when libc++ is in use** #4319).Suggested changelog entry
Guard the
<cxxabi.h>include with__has_includeso that toolchains defining__GNUG__without the header (e.g. clang-cl) can compiledetail/typeid.h.