diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8607ee98..c5c75146f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,20 +88,20 @@ jobs: # Extra ubuntu latest job - runs-on: ubuntu-latest python: '3.11' - # Exercise PYBIND11_USE_SMART_HOLDER_AS_DEFAULT + # Run tests with py::smart_holder as the default holder # with recent (or ideally latest) released Python version. - runs-on: ubuntu-latest python: '3.12' args: > - -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" + -DCMAKE_CXX_FLAGS="-DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE" - runs-on: macos-13 python: '3.12' args: > - -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" + -DCMAKE_CXX_FLAGS="-DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE" - runs-on: windows-2022 python: '3.12' args: > - -DCMAKE_CXX_FLAGS="/DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT /GR /EHsc" + -DCMAKE_CXX_FLAGS="/DPYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE /GR /EHsc" exclude: # The setup-python action currently doesn't have graalpy for windows - python: 'graalpy-24.1' diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 5564f040e..3b06eb548 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1839,14 +1839,13 @@ struct property_cpp_function< detail::both_t_and_d_use_type_caster_base>::value>> : detail::property_cpp_function_sh_unique_ptr_member {}; -#if defined(PYBIND11_USE_SMART_HOLDER_AS_DEFAULT) -// NOTE: THIS IS MEANT FOR STRESS-TESTING ONLY! -// As of PR #5257, for production use, there is no longer a strong reason to make -// smart_holder the default holder: -// Simply use `py::classh` (see below) instead of `py::class_` as needed. +#ifdef PYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE +// NOTE: THIS IS MEANT FOR STRESS-TESTING OR TRIAGING ONLY! // Running the pybind11 unit tests with smart_holder as the default holder is to ensure // that `py::smart_holder` / `py::classh` is backward-compatible with all pre-existing // functionality. +// Be careful not to link translation units compiled with different default holders, because +// this will cause ODR violations (https://en.wikipedia.org/wiki/One_Definition_Rule). template using default_holder_type = smart_holder; #else diff --git a/tests/test_class.cpp b/tests/test_class.cpp index 86c8d3701..28dc31333 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -632,7 +632,7 @@ CHECK_NOALIAS(8); CHECK_HOLDER(1, unique); CHECK_HOLDER(2, unique); CHECK_HOLDER(3, unique); -#ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT +#ifndef PYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE CHECK_HOLDER(4, unique); CHECK_HOLDER(5, unique); #endif