@@ -204,7 +204,7 @@ class cpp_function : public function {
204204 auto *rec = unique_rec.get ();
205205
206206 /* Store the capture object directly in the function record if there is enough space */
207- if (sizeof (capture) <= sizeof (rec->data )) {
207+ if PYBIND11_IF_CONSTEXPR (sizeof (capture) <= sizeof (rec->data )) {
208208 /* Without these pragmas, GCC warns that there might not be
209209 enough space to use the placement new operator. However, the
210210 'if' statement above ensures that this is the case. */
@@ -222,7 +222,7 @@ class cpp_function : public function {
222222
223223 // UB without std::launder, but without breaking ABI and/or
224224 // a significant refactoring it's "impossible" to solve.
225- if (!std::is_trivially_destructible<capture>::value) {
225+ if PYBIND11_IF_CONSTEXPR (!std::is_trivially_destructible<capture>::value) {
226226 rec->free_data = [](function_record *r) {
227227 auto data = PYBIND11_STD_LAUNDER ((capture *) &r->data );
228228 (void ) data;
@@ -331,7 +331,7 @@ class cpp_function : public function {
331331 using FunctionType = Return (*)(Args...);
332332 constexpr bool is_function_ptr
333333 = std::is_convertible<Func, FunctionType>::value && sizeof (capture) == sizeof (void *);
334- if (is_function_ptr) {
334+ if PYBIND11_IF_CONSTEXPR (is_function_ptr) {
335335 rec->is_stateless = true ;
336336 rec->data [1 ]
337337 = const_cast <void *>(reinterpret_cast <const void *>(&typeid (FunctionType)));
@@ -1605,7 +1605,7 @@ class class_ : public detail::generic_type {
16051605
16061606 generic_type::initialize (record);
16071607
1608- if (has_alias) {
1608+ if PYBIND11_IF_CONSTEXPR (has_alias) {
16091609 with_internals ([&](internals &internals) {
16101610 auto &instances = record.module_local ? get_local_internals ().registered_types_cpp
16111611 : internals.registered_types_cpp ;
@@ -2011,7 +2011,8 @@ inline str enum_name(handle arg) {
20112011struct enum_base {
20122012 enum_base (const handle &base, const handle &parent) : m_base(base), m_parent(parent) {}
20132013
2014- PYBIND11_NOINLINE void init (bool is_arithmetic, bool is_convertible) {
2014+ template <bool is_arithmetic, bool is_convertible>
2015+ PYBIND11_NOINLINE void init () {
20152016 m_base.attr (" __entries" ) = dict ();
20162017 auto property = handle ((PyObject *) &PyProperty_Type);
20172018 auto static_property = handle ((PyObject *) get_internals ().static_property_type );
@@ -2111,11 +2112,11 @@ struct enum_base {
21112112 is_method (m_base), \
21122113 arg (" other" ))
21132114
2114- if (is_convertible) {
2115+ if PYBIND11_IF_CONSTEXPR (is_convertible) {
21152116 PYBIND11_ENUM_OP_CONV_LHS (" __eq__" , !b.is_none () && a.equal (b));
21162117 PYBIND11_ENUM_OP_CONV_LHS (" __ne__" , b.is_none () || !a.equal (b));
21172118
2118- if (is_arithmetic) {
2119+ if PYBIND11_IF_CONSTEXPR (is_arithmetic) {
21192120 PYBIND11_ENUM_OP_CONV (" __lt__" , a < b);
21202121 PYBIND11_ENUM_OP_CONV (" __gt__" , a > b);
21212122 PYBIND11_ENUM_OP_CONV (" __le__" , a <= b);
@@ -2135,7 +2136,7 @@ struct enum_base {
21352136 PYBIND11_ENUM_OP_STRICT (" __eq__" , int_ (a).equal (int_ (b)), return false );
21362137 PYBIND11_ENUM_OP_STRICT (" __ne__" , !int_ (a).equal (int_ (b)), return true );
21372138
2138- if (is_arithmetic) {
2139+ if PYBIND11_IF_CONSTEXPR (is_arithmetic) {
21392140#define PYBIND11_THROW throw type_error (" Expected an enumeration of matching type!" );
21402141 PYBIND11_ENUM_OP_STRICT (" __lt__" , int_ (a) < int_ (b), PYBIND11_THROW);
21412142 PYBIND11_ENUM_OP_STRICT (" __gt__" , int_ (a) > int_ (b), PYBIND11_THROW);
@@ -2242,7 +2243,7 @@ class enum_ : public class_<Type> {
22422243 : class_<Type>(scope, name, extra...), m_base(*this , scope) {
22432244 constexpr bool is_arithmetic = detail::any_of<std::is_same<arithmetic, Extra>...>::value;
22442245 constexpr bool is_convertible = std::is_convertible<Type, Underlying>::value;
2245- m_base.init ( is_arithmetic, is_convertible);
2246+ m_base.init < is_arithmetic, is_convertible>( );
22462247
22472248 def (init ([](Scalar i) { return static_cast <Type>(i); }), arg (" value" ));
22482249 def_property_readonly (" value" , [](Type value) { return (Scalar) value; });
0 commit comments