diff --git a/include/pybind11/detail/typeid.h b/include/pybind11/detail/typeid.h index a67b52135b..fa5bfe1645 100644 --- a/include/pybind11/detail/typeid.h +++ b/include/pybind11/detail/typeid.h @@ -13,6 +13,16 @@ #include #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 +# endif +#endif +#if defined(PYBIND11_HAS_CXXABI_H) # include #endif @@ -33,7 +43,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};