Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion include/pybind11/detail/typeid.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
#include <cstdlib>

#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

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
# define PYBIND11_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).
# define PYBIND11_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.

# elif __has_include(<cxxabi.h>)
# define PYBIND11_HAS_CXXABI_H
# endif
#endif
#if defined(PYBIND11_HAS_CXXABI_H)
# include <cxxabi.h>
#endif

Expand All @@ -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<char, void (*)(void *)> res{
abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free};
Expand Down
Loading