From d91d0885bf537e9525a75898ad62f6c29d3d2dca Mon Sep 17 00:00:00 2001 From: aidaodedjl Date: Sun, 16 Aug 2026 13:33:24 +0800 Subject: [PATCH 1/2] fix: guard cxxabi.h include with __has_include for clang-cl clang-cl on Windows defines __GNUG__ but does not ship , making detail/typeid.h fail to compile. Introduce PYBIND11_HAS_CXXABI_H, defined only when 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. Fixes #6129 --- include/pybind11/detail/typeid.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/pybind11/detail/typeid.h b/include/pybind11/detail/typeid.h index a67b52135b..969fce2645 100644 --- a/include/pybind11/detail/typeid.h +++ b/include/pybind11/detail/typeid.h @@ -13,6 +13,13 @@ #include #if defined(__GNUG__) +# if !defined(__has_include) +# define PYBIND11_HAS_CXXABI_H +# elif __has_include() +# define PYBIND11_HAS_CXXABI_H +# endif +#endif +#if defined(PYBIND11_HAS_CXXABI_H) # include #endif @@ -33,7 +40,7 @@ inline void erase_all(std::string &string, const std::string &search) { } PYBIND11_NOINLINE void clean_type_id(std::string &name) { -#if defined(__GNUG__) +#if defined(PYBIND11_HAS_CXXABI_H) int status = 0; std::unique_ptr res{ abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free}; From 0fee21e9aaa8cc3aaf86eff11481202c642b6bff Mon Sep 17 00:00:00 2001 From: aidaodedjl Date: Mon, 17 Aug 2026 01:31:45 +0800 Subject: [PATCH 2/2] docs: explain the __has_include fallback for GCC < 5 --- include/pybind11/detail/typeid.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/pybind11/detail/typeid.h b/include/pybind11/detail/typeid.h index 969fce2645..fa5bfe1645 100644 --- a/include/pybind11/detail/typeid.h +++ b/include/pybind11/detail/typeid.h @@ -14,6 +14,9 @@ #if defined(__GNUG__) # if !defined(__has_include) +// 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). # define PYBIND11_HAS_CXXABI_H # elif __has_include() # define PYBIND11_HAS_CXXABI_H