Use no-destructor idiom for type_caster_odr_guard_registry, as suggested by @laramiel

This commit is contained in:
Ralf W. Grosse-Kunstleve 2022-07-15 11:19:50 -07:00
parent 671c2ce0d5
commit 696b80a59b

View File

@ -28,9 +28,12 @@
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail) PYBIND11_NAMESPACE_BEGIN(detail)
inline std::unordered_map<std::type_index, std::string> &type_caster_odr_guard_registry() { using type_caster_odr_guard_registry_type = std::unordered_map<std::type_index, std::string>;
static std::unordered_map<std::type_index, std::string> reg;
return reg; inline type_caster_odr_guard_registry_type &type_caster_odr_guard_registry() {
// Using the no-destructor idiom (maximizes safety).
static auto reg = new type_caster_odr_guard_registry_type();
return *reg;
} }
inline unsigned &type_caster_odr_violation_detected_counter() { inline unsigned &type_caster_odr_violation_detected_counter() {