diff --git a/include/pybind11/common.h b/include/pybind11/common.h index ddf966ea7..baa84b2c5 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -504,6 +504,14 @@ struct is_input_iterator()), decltype(++st /// Ignore that a variable is unused in compiler warnings inline void ignore_unused(const int *) { } +/// Apply a function over each element of a parameter pack +#ifdef __cpp_fold_expressions +#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (((PATTERN), void()), ...) +#else +using expand_side_effects = bool[]; +#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false } +#endif + NAMESPACE_END(detail) /// Returns a named pointer that is shared among all extension modules (using the same diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index c4e6131e4..21d911cdf 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -947,8 +947,7 @@ public: set_operator_new(&record); /* Register base classes specified via template arguments to class_, if any */ - bool unused[] = { (add_base(record), false)..., false }; - (void) unused; + PYBIND11_EXPAND_SIDE_EFFECTS(add_base(record)); /* Process optional arguments, if any */ process_attributes::init(extra..., &record);