Skip to content

Commit d91d088

Browse files
author
aidaodedjl
committed
fix: guard cxxabi.h include with __has_include for clang-cl
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. Fixes #6129
1 parent 0599909 commit d91d088

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

include/pybind11/detail/typeid.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
#include <cstdlib>
1414

1515
#if defined(__GNUG__)
16+
# if !defined(__has_include)
17+
# define PYBIND11_HAS_CXXABI_H
18+
# elif __has_include(<cxxabi.h>)
19+
# define PYBIND11_HAS_CXXABI_H
20+
# endif
21+
#endif
22+
#if defined(PYBIND11_HAS_CXXABI_H)
1623
# include <cxxabi.h>
1724
#endif
1825

@@ -33,7 +40,7 @@ inline void erase_all(std::string &string, const std::string &search) {
3340
}
3441

3542
PYBIND11_NOINLINE void clean_type_id(std::string &name) {
36-
#if defined(__GNUG__)
43+
#if defined(PYBIND11_HAS_CXXABI_H)
3744
int status = 0;
3845
std::unique_ptr<char, void (*)(void *)> res{
3946
abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free};

0 commit comments

Comments
 (0)