From ffa9bbec0a1e32f3af99d6bd8cc23bb3fccd6e1b Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Fri, 21 Aug 2026 10:17:02 -0700 Subject: [PATCH] (BE)(NFC): Use much more specific CPP feature flags --- include/pybind11/complex.h | 2 +- include/pybind11/detail/common.h | 7 ++++--- include/pybind11/detail/init.h | 6 +++--- include/pybind11/pybind11.h | 2 +- tests/test_class.cpp | 3 ++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/pybind11/complex.h b/include/pybind11/complex.h index a6ec11a462..9d0812f09f 100644 --- a/include/pybind11/complex.h +++ b/include/pybind11/complex.h @@ -27,7 +27,7 @@ struct format_descriptor, detail::enable_if_t constexpr const char diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 740001db78..c8fff5c144 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -1202,7 +1202,7 @@ struct format_descriptor::value>> { static std::string format() { return std::string(1, c); } }; -#if !defined(PYBIND11_CPP17) +#if !defined(__cpp_inline_variables) || __cpp_inline_variables < 201606L template constexpr const char @@ -1278,7 +1278,7 @@ struct overload_cast_impl { PYBIND11_NAMESPACE_END(detail) // overload_cast requires variable templates: C++14 -#if defined(PYBIND11_CPP14) +#if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304L # define PYBIND11_OVERLOAD_CAST 1 /// Syntax sugar for resolving overloaded function pointers: /// - regular: static_cast(&Class::func) @@ -1292,7 +1292,8 @@ static constexpr detail::overload_cast_impl overload_cast{}; /// - sweet: overload_cast(&Class::func, const_) static constexpr auto const_ = std::true_type{}; -#if !defined(PYBIND11_CPP14) // no overload_cast: providing something that static_assert-fails: +#if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L +// No overload_cast: providing something that static_assert-fails. template struct overload_cast { static_assert(detail::deferred_t::value, diff --git a/include/pybind11/detail/init.h b/include/pybind11/detail/init.h index a1083f8457..5f9e925c3f 100644 --- a/include/pybind11/detail/init.h +++ b/include/pybind11/detail/init.h @@ -388,7 +388,7 @@ struct factory { // instance, or the alias needs to be constructible from a `Class &&` argument. template void execute(Class &cl, const Extra &...extra) && { -#if defined(PYBIND11_CPP14) +#if defined(__cpp_init_captures) && __cpp_init_captures >= 201304L cl.def( "__init__", [func = std::move(class_factory)] @@ -435,7 +435,7 @@ struct factory { static_assert(Class::has_alias, "The two-argument version of `py::init()` can " "only be used if the class has an alias"); -#if defined(PYBIND11_CPP14) +#if defined(__cpp_init_captures) && __cpp_init_captures >= 201304L cl.def( "__init__", [class_func = std::move(class_factory), alias_func = std::move(alias_factory)] @@ -524,7 +524,7 @@ struct pickle_factory { void execute(Class &cl, const Extra &...extra) && { cl.def("__getstate__", std::move(get), pos_only()); -#if defined(PYBIND11_CPP14) +#if defined(__cpp_init_captures) && __cpp_init_captures >= 201304L cl.def( "__setstate__", [func = std::move(set)] diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index eebb130694..f57514ae28 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -294,7 +294,7 @@ class ReadableFunctionSignature { // Prior to C++17, we don't have inline variables, so we have to // provide an out-of-line definition of the class member. -#if !defined(PYBIND11_CPP17) +#if !defined(__cpp_inline_variables) || __cpp_inline_variables < 201606L template constexpr typename ReadableFunctionSignature::sig_type ReadableFunctionSignature::kSig; diff --git a/tests/test_class.cpp b/tests/test_class.cpp index 84efb800db..e520f29ec5 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -516,7 +516,8 @@ TEST_SUBMODULE(class_, m) { py::class_(m, "StringWrapper").def(py::init()); py::implicitly_convertible(); -#if defined(PYBIND11_CPP17) +#if (defined(__cpp_aligned_new) && __cpp_aligned_new >= 201606L) \ + || (defined(__INTEL_COMPILER) && __cplusplus >= 201703L) struct alignas(1024) Aligned { std::uintptr_t ptr() const { return (uintptr_t) this; } };