diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 970a0cd9a..9c4cf4741 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -904,7 +904,12 @@ struct polymorphic_type_hook : public polymorphic_type_hook_base {}; PYBIND11_NAMESPACE_BEGIN(detail) -#define PYBIND11_TYPE_CASTER_ODR_GUARD_ON +#if !defined(PYBIND11_TYPE_CASTER_ODR_GUARD_ON) && !defined(PYBIND11_TYPE_CASTER_ODR_GUARD_OFF) \ + && (defined(_MSC_VER) || defined(PYBIND11_CPP20) \ + || (defined(PYBIND11_CPP17) && defined(__clang__))) +# define PYBIND11_TYPE_CASTER_ODR_GUARD_ON +#endif + #ifdef PYBIND11_TYPE_CASTER_ODR_GUARD_ON namespace {