@@ -399,7 +399,7 @@ class cpp_function : public function {
399399 auto *rec = unique_rec.get ();
400400
401401 /* Store the capture object directly in the function record if there is enough space */
402- if (sizeof (capture) <= sizeof (rec->data )) {
402+ if PYBIND11_IF_CONSTEXPR (sizeof (capture) <= sizeof (rec->data )) {
403403 /* Without these pragmas, GCC warns that there might not be
404404 enough space to use the placement new operator. However, the
405405 'if' statement above ensures that this is the case. */
@@ -417,7 +417,7 @@ class cpp_function : public function {
417417
418418 // UB without std::launder, but without breaking ABI and/or
419419 // a significant refactoring it's "impossible" to solve.
420- if (!std::is_trivially_destructible<capture>::value) {
420+ if PYBIND11_IF_CONSTEXPR (!std::is_trivially_destructible<capture>::value) {
421421 rec->free_data = [](function_record *r) {
422422 auto data = capture::from_data (r->data );
423423 (void ) data; // suppress "unused variable" warnings
@@ -2189,7 +2189,7 @@ class class_ : public detail::generic_type {
21892189
21902190 generic_type::initialize (record);
21912191
2192- if (has_alias) {
2192+ if PYBIND11_IF_CONSTEXPR (has_alias) {
21932193 with_internals ([&](internals &internals) {
21942194 auto &local_internals = get_local_internals ();
21952195 if (record.module_local ) {
@@ -2696,7 +2696,8 @@ inline str enum_name(handle arg) {
26962696struct enum_base {
26972697 enum_base (const handle &base, const handle &parent) : m_base(base), m_parent(parent) {}
26982698
2699- PYBIND11_NOINLINE void init (bool is_arithmetic, bool is_convertible) {
2699+ template <bool is_arithmetic, bool is_convertible>
2700+ PYBIND11_NOINLINE void init () {
27002701 m_base.attr (" __entries" ) = dict ();
27012702 auto property = handle ((PyObject *) &PyProperty_Type);
27022703 auto static_property = handle ((PyObject *) get_internals ().static_property_type );
@@ -2802,11 +2803,11 @@ struct enum_base {
28022803 arg (" other" ), \
28032804 pos_only ())
28042805
2805- if (is_convertible) {
2806+ if PYBIND11_IF_CONSTEXPR (is_convertible) {
28062807 PYBIND11_ENUM_OP_CONV_LHS (" __eq__" , !b.is_none () && a.equal (b));
28072808 PYBIND11_ENUM_OP_CONV_LHS (" __ne__" , b.is_none () || !a.equal (b));
28082809
2809- if (is_arithmetic) {
2810+ if PYBIND11_IF_CONSTEXPR (is_arithmetic) {
28102811 PYBIND11_ENUM_OP_CONV (" __lt__" , a < b);
28112812 PYBIND11_ENUM_OP_CONV (" __gt__" , a > b);
28122813 PYBIND11_ENUM_OP_CONV (" __le__" , a <= b);
@@ -2827,7 +2828,7 @@ struct enum_base {
28272828 PYBIND11_ENUM_OP_STRICT (" __eq__" , int_ (a).equal (int_ (b)), return false );
28282829 PYBIND11_ENUM_OP_STRICT (" __ne__" , !int_ (a).equal (int_ (b)), return true );
28292830
2830- if (is_arithmetic) {
2831+ if PYBIND11_IF_CONSTEXPR (is_arithmetic) {
28312832#define PYBIND11_THROW throw type_error (" Expected an enumeration of matching type!" );
28322833 PYBIND11_ENUM_OP_STRICT (" __lt__" , int_ (a) < int_ (b), PYBIND11_THROW);
28332834 PYBIND11_ENUM_OP_STRICT (" __gt__" , int_ (a) > int_ (b), PYBIND11_THROW);
@@ -2946,7 +2947,7 @@ class enum_ : public class_<Type> {
29462947
29472948 constexpr bool is_arithmetic = detail::any_of<std::is_same<arithmetic, Extra>...>::value;
29482949 constexpr bool is_convertible = std::is_convertible<Type, Underlying>::value;
2949- m_base.init ( is_arithmetic, is_convertible);
2950+ m_base.init < is_arithmetic, is_convertible>( );
29502951
29512952 def (init ([](Scalar i) { return static_cast <Type>(i); }), arg (" value" ));
29522953 def_property_readonly (" value" , [](Type value) { return (Scalar) value; }, pos_only ());
0 commit comments