From 8581584e6091cd09372dcc3d51670b118c4847cc Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 7 Feb 2022 16:17:32 -0800 Subject: [PATCH] Manual fix-ups in preparation for clang-tidy readability-braces-around-statements. Informed by experiments under PR #3698. --- include/pybind11/cast.h | 16 ++++++++++------ include/pybind11/detail/init.h | 5 +++-- include/pybind11/detail/type_caster_base.h | 15 ++++++++++----- include/pybind11/pybind11.h | 3 ++- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 165102443c..a392400870 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -915,7 +915,7 @@ template <> inline void handle::cast() const { return; } template detail::enable_if_t::value, T> move(object &&obj) { - if (obj.ref_count() > 1) + if (obj.ref_count() > 1) { #if defined(NDEBUG) throw cast_error("Unable to cast Python instance to C++ rvalue: instance has multiple references" " (compile in debug mode for details)"); @@ -923,6 +923,7 @@ detail::enable_if_t::value, T> move(object &&obj) { throw cast_error("Unable to move from Python " + (std::string) str(type::handle_of(obj)) + " instance to C++ " + type_id() + " instance: instance has multiple references"); #endif + } // Move into a temporary and return that, because the reference may be a local value of `conv` T ret = std::move(detail::load_type(obj).operator T&()); @@ -1192,12 +1193,15 @@ class argument_loader { template bool load_impl_sequence(function_call &call, index_sequence) { #ifdef __cpp_fold_expressions - if ((... || !std::get(argcasters).load(call.args[Is], call.args_convert[Is]))) + if ((... || !std::get(argcasters).load(call.args[Is], call.args_convert[Is]))) { return false; + } #else - for (bool r : {std::get(argcasters).load(call.args[Is], call.args_convert[Is])...}) - if (!r) + for (bool r : {std::get(argcasters).load(call.args[Is], call.args_convert[Is])...}) { + if (!r) { return false; + } + } #endif return true; } @@ -1286,13 +1290,13 @@ class unpacking_collector { } void process(list &/*args_list*/, arg_v a) { - if (!a.name) + if (!a.name) { #if defined(NDEBUG) nameless_argument_error(); #else nameless_argument_error(a.type); #endif - + } if (m_kwargs.contains(a.name)) { #if defined(NDEBUG) multiple_values_error(); diff --git a/include/pybind11/detail/init.h b/include/pybind11/detail/init.h index eaaad5a07a..65b823e549 100644 --- a/include/pybind11/detail/init.h +++ b/include/pybind11/detail/init.h @@ -276,12 +276,13 @@ struct factory { cl.def("__init__", [class_func, alias_func] #endif (value_and_holder &v_h, CArgs... args) { - if (Py_TYPE(v_h.inst) == v_h.type->type) + if (Py_TYPE(v_h.inst) == v_h.type->type) { // If the instance type equals the registered type we don't have inheritance, so // don't need the alias and can construct using the class function: construct(v_h, class_func(std::forward(args)...), false); - else + } else { construct(v_h, alias_func(std::forward(args)...), true); + } }, is_new_style_constructor(), extra...); } }; diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 48e218b2f3..87a4087a01 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -625,12 +625,15 @@ class type_caster_generic { vptr = type->operator_new(type->type_size); } else { #if defined(__cpp_aligned_new) && (!defined(_MSC_VER) || _MSC_VER >= 1912) - if (type->type_align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + if (type->type_align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { vptr = ::operator new(type->type_size, std::align_val_t(type->type_align)); - else + } else { + vptr = ::operator new(type->type_size); + } + #else + vptr = ::operator new(type->type_size); #endif - vptr = ::operator new(type->type_size); } } value = vptr; @@ -778,8 +781,9 @@ class type_caster_generic { // with .second = nullptr. (p.first = nullptr is not an error: it becomes None). PYBIND11_NOINLINE static std::pair src_and_type( const void *src, const std::type_info &cast_type, const std::type_info *rtti_type = nullptr) { - if (auto *tpi = get_type_info(cast_type)) + if (auto *tpi = get_type_info(cast_type)) { return {src, const_cast(tpi)}; + } // Not found, set error: std::string tname = rtti_type ? rtti_type->name() : cast_type.name(); @@ -928,8 +932,9 @@ template class type_caster_base : public type_caster_generic { // except via a user-provided specialization of polymorphic_type_hook, // and the user has promised that no this-pointer adjustment is // required in that case, so it's OK to use static_cast. - if (const auto *tpi = get_type_info(*instance_type)) + if (const auto *tpi = get_type_info(*instance_type)) { return {vsrc, tpi}; + } } // Otherwise we have either a nullptr, an `itype` pointer, or an unknown derived pointer, so // don't do a cast diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 7dcea95b42..b64d426869 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -183,12 +183,13 @@ class cpp_function : public function { #endif // UB without std::launder, but without breaking ABI and/or // a significant refactoring it's "impossible" to solve. - if (!std::is_trivially_destructible::value) + if (!std::is_trivially_destructible::value) { rec->free_data = [](function_record *r) { auto data = PYBIND11_STD_LAUNDER((capture *) &r->data); (void) data; data->~capture(); }; + } #if defined(__GNUG__) && !PYBIND11_HAS_STD_LAUNDER && !defined(__INTEL_COMPILER) # pragma GCC diagnostic pop #endif