@@ -204,7 +204,7 @@ class cpp_function : public function {
204
204
auto *rec = unique_rec.get ();
205
205
206
206
/* 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 )) {
208
208
/* Without these pragmas, GCC warns that there might not be
209
209
enough space to use the placement new operator. However, the
210
210
'if' statement above ensures that this is the case. */
@@ -222,7 +222,7 @@ class cpp_function : public function {
222
222
223
223
// UB without std::launder, but without breaking ABI and/or
224
224
// 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) {
226
226
rec->free_data = [](function_record *r) {
227
227
auto data = PYBIND11_STD_LAUNDER ((capture *) &r->data );
228
228
(void ) data;
@@ -331,7 +331,7 @@ class cpp_function : public function {
331
331
using FunctionType = Return (*)(Args...);
332
332
constexpr bool is_function_ptr
333
333
= std::is_convertible<Func, FunctionType>::value && sizeof (capture) == sizeof (void *);
334
- if (is_function_ptr) {
334
+ if PYBIND11_IF_CONSTEXPR (is_function_ptr) {
335
335
rec->is_stateless = true ;
336
336
rec->data [1 ]
337
337
= const_cast <void *>(reinterpret_cast <const void *>(&typeid (FunctionType)));
@@ -1605,7 +1605,7 @@ class class_ : public detail::generic_type {
1605
1605
1606
1606
generic_type::initialize (record);
1607
1607
1608
- if (has_alias) {
1608
+ if PYBIND11_IF_CONSTEXPR (has_alias) {
1609
1609
with_internals ([&](internals &internals) {
1610
1610
auto &instances = record.module_local ? get_local_internals ().registered_types_cpp
1611
1611
: internals.registered_types_cpp ;
@@ -2011,7 +2011,8 @@ inline str enum_name(handle arg) {
2011
2011
struct enum_base {
2012
2012
enum_base (const handle &base, const handle &parent) : m_base(base), m_parent(parent) {}
2013
2013
2014
- PYBIND11_NOINLINE void init (bool is_arithmetic, bool is_convertible) {
2014
+ template <bool is_arithmetic, bool is_convertible>
2015
+ PYBIND11_NOINLINE void init () {
2015
2016
m_base.attr (" __entries" ) = dict ();
2016
2017
auto property = handle ((PyObject *) &PyProperty_Type);
2017
2018
auto static_property = handle ((PyObject *) get_internals ().static_property_type );
@@ -2111,11 +2112,11 @@ struct enum_base {
2111
2112
is_method (m_base), \
2112
2113
arg (" other" ))
2113
2114
2114
- if (is_convertible) {
2115
+ if PYBIND11_IF_CONSTEXPR (is_convertible) {
2115
2116
PYBIND11_ENUM_OP_CONV_LHS (" __eq__" , !b.is_none () && a.equal (b));
2116
2117
PYBIND11_ENUM_OP_CONV_LHS (" __ne__" , b.is_none () || !a.equal (b));
2117
2118
2118
- if (is_arithmetic) {
2119
+ if PYBIND11_IF_CONSTEXPR (is_arithmetic) {
2119
2120
PYBIND11_ENUM_OP_CONV (" __lt__" , a < b);
2120
2121
PYBIND11_ENUM_OP_CONV (" __gt__" , a > b);
2121
2122
PYBIND11_ENUM_OP_CONV (" __le__" , a <= b);
@@ -2135,7 +2136,7 @@ struct enum_base {
2135
2136
PYBIND11_ENUM_OP_STRICT (" __eq__" , int_ (a).equal (int_ (b)), return false );
2136
2137
PYBIND11_ENUM_OP_STRICT (" __ne__" , !int_ (a).equal (int_ (b)), return true );
2137
2138
2138
- if (is_arithmetic) {
2139
+ if PYBIND11_IF_CONSTEXPR (is_arithmetic) {
2139
2140
#define PYBIND11_THROW throw type_error (" Expected an enumeration of matching type!" );
2140
2141
PYBIND11_ENUM_OP_STRICT (" __lt__" , int_ (a) < int_ (b), PYBIND11_THROW);
2141
2142
PYBIND11_ENUM_OP_STRICT (" __gt__" , int_ (a) > int_ (b), PYBIND11_THROW);
@@ -2242,7 +2243,7 @@ class enum_ : public class_<Type> {
2242
2243
: class_<Type>(scope, name, extra...), m_base(*this , scope) {
2243
2244
constexpr bool is_arithmetic = detail::any_of<std::is_same<arithmetic, Extra>...>::value;
2244
2245
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>( );
2246
2247
2247
2248
def (init ([](Scalar i) { return static_cast <Type>(i); }), arg (" value" ));
2248
2249
def_property_readonly (" value" , [](Type value) { return (Scalar) value; });
0 commit comments