From 2e6e83392962995541c810a684c6aada3ca67400 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 22 Jun 2022 08:09:54 -0700 Subject: [PATCH] Move type_caster_odr_guard to type_caster_odr_guard.h --- include/pybind11/cast.h | 19 +------------------ .../pybind11/detail/type_caster_odr_guard.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 55b20c9a5..3097b0bb4 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -47,25 +47,8 @@ class type_caster : public type_caster_for_class_ {}; #ifdef PYBIND11_TYPE_CASTER_ODR_GUARD_ON -namespace { - -template -struct type_caster_odr_guard : type_caster { - static int translation_unit_local; -}; - -template -int type_caster_odr_guard::translation_unit_local = []() { - type_caster_odr_guard_impl(typeid(IntrinsicType), - type_caster::source_file_line.text, - PYBIND11_DETAIL_TYPE_CASTER_ODR_GUARD_IMPL_THROW_DISABLED); - return 0; -}(); - -} // namespace - template -using make_caster = type_caster_odr_guard>; +using make_caster = type_caster_odr_guard, type_caster>>; #else // !PYBIND11_TYPE_CASTER_ODR_GUARD_ON diff --git a/include/pybind11/detail/type_caster_odr_guard.h b/include/pybind11/detail/type_caster_odr_guard.h index 355088a40..b79f927d3 100644 --- a/include/pybind11/detail/type_caster_odr_guard.h +++ b/include/pybind11/detail/type_caster_odr_guard.h @@ -106,8 +106,27 @@ constexpr tu_local_descr tu_local_const_name(char const (&text)[N]) { } constexpr tu_local_descr<0> tu_local_const_name(char const (&)[1]) { return {}; } +struct tu_local_no_data_always_false { + operator bool() const noexcept { return false; } +}; + } // namespace +template +struct type_caster_odr_guard : TypeCasterType { + static tu_local_no_data_always_false translation_unit_local; +}; + +template +tu_local_no_data_always_false + type_caster_odr_guard::translation_unit_local + = []() { + type_caster_odr_guard_impl(typeid(IntrinsicType), + TypeCasterType::source_file_line.text, + PYBIND11_DETAIL_TYPE_CASTER_ODR_GUARD_IMPL_THROW_DISABLED); + return tu_local_no_data_always_false(); + }(); + PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)