Manual fix-ups in preparation for clang-tidy readability-braces-around-statements.

Informed by experiments under PR #3698.
This commit is contained in:
Ralf W. Grosse-Kunstleve 2022-02-07 16:17:32 -08:00 committed by Ralf W. Grosse-Kunstleve
parent af056b65d3
commit 8581584e60
4 changed files with 25 additions and 14 deletions

View File

@ -915,7 +915,7 @@ template <> inline void handle::cast() const { return; }
template <typename T> template <typename T>
detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) { detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) {
if (obj.ref_count() > 1) if (obj.ref_count() > 1) {
#if defined(NDEBUG) #if defined(NDEBUG)
throw cast_error("Unable to cast Python instance to C++ rvalue: instance has multiple references" throw cast_error("Unable to cast Python instance to C++ rvalue: instance has multiple references"
" (compile in debug mode for details)"); " (compile in debug mode for details)");
@ -923,6 +923,7 @@ detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) {
throw cast_error("Unable to move from Python " + (std::string) str(type::handle_of(obj)) + throw cast_error("Unable to move from Python " + (std::string) str(type::handle_of(obj)) +
" instance to C++ " + type_id<T>() + " instance: instance has multiple references"); " instance to C++ " + type_id<T>() + " instance: instance has multiple references");
#endif #endif
}
// Move into a temporary and return that, because the reference may be a local value of `conv` // Move into a temporary and return that, because the reference may be a local value of `conv`
T ret = std::move(detail::load_type<T>(obj).operator T&()); T ret = std::move(detail::load_type<T>(obj).operator T&());
@ -1192,12 +1193,15 @@ private:
template <size_t... Is> template <size_t... Is>
bool load_impl_sequence(function_call &call, index_sequence<Is...>) { bool load_impl_sequence(function_call &call, index_sequence<Is...>) {
#ifdef __cpp_fold_expressions #ifdef __cpp_fold_expressions
if ((... || !std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is]))) if ((... || !std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is]))) {
return false; return false;
}
#else #else
for (bool r : {std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is])...}) for (bool r : {std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is])...}) {
if (!r) if (!r) {
return false; return false;
}
}
#endif #endif
return true; return true;
} }
@ -1286,13 +1290,13 @@ private:
} }
void process(list &/*args_list*/, arg_v a) { void process(list &/*args_list*/, arg_v a) {
if (!a.name) if (!a.name) {
#if defined(NDEBUG) #if defined(NDEBUG)
nameless_argument_error(); nameless_argument_error();
#else #else
nameless_argument_error(a.type); nameless_argument_error(a.type);
#endif #endif
}
if (m_kwargs.contains(a.name)) { if (m_kwargs.contains(a.name)) {
#if defined(NDEBUG) #if defined(NDEBUG)
multiple_values_error(); multiple_values_error();

View File

@ -276,12 +276,13 @@ struct factory<CFunc, AFunc, CReturn(CArgs...), AReturn(AArgs...)> {
cl.def("__init__", [class_func, alias_func] cl.def("__init__", [class_func, alias_func]
#endif #endif
(value_and_holder &v_h, CArgs... args) { (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 // 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: // don't need the alias and can construct using the class function:
construct<Class>(v_h, class_func(std::forward<CArgs>(args)...), false); construct<Class>(v_h, class_func(std::forward<CArgs>(args)...), false);
else } else {
construct<Class>(v_h, alias_func(std::forward<CArgs>(args)...), true); construct<Class>(v_h, alias_func(std::forward<CArgs>(args)...), true);
}
}, is_new_style_constructor(), extra...); }, is_new_style_constructor(), extra...);
} }
}; };

View File

@ -625,13 +625,16 @@ public:
vptr = type->operator_new(type->type_size); vptr = type->operator_new(type->type_size);
} else { } else {
#if defined(__cpp_aligned_new) && (!defined(_MSC_VER) || _MSC_VER >= 1912) #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, vptr = ::operator new(type->type_size,
std::align_val_t(type->type_align)); std::align_val_t(type->type_align));
else } else {
#endif
vptr = ::operator new(type->type_size); vptr = ::operator new(type->type_size);
} }
#else
vptr = ::operator new(type->type_size);
#endif
}
} }
value = vptr; value = vptr;
} }
@ -778,8 +781,9 @@ public:
// with .second = nullptr. (p.first = nullptr is not an error: it becomes None). // with .second = nullptr. (p.first = nullptr is not an error: it becomes None).
PYBIND11_NOINLINE static std::pair<const void *, const type_info *> src_and_type( PYBIND11_NOINLINE static std::pair<const void *, const type_info *> src_and_type(
const void *src, const std::type_info &cast_type, const std::type_info *rtti_type = nullptr) { 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<const type_info *>(tpi)}; return {src, const_cast<const type_info *>(tpi)};
}
// Not found, set error: // Not found, set error:
std::string tname = rtti_type ? rtti_type->name() : cast_type.name(); std::string tname = rtti_type ? rtti_type->name() : cast_type.name();
@ -928,9 +932,10 @@ public:
// except via a user-provided specialization of polymorphic_type_hook, // except via a user-provided specialization of polymorphic_type_hook,
// and the user has promised that no this-pointer adjustment is // and the user has promised that no this-pointer adjustment is
// required in that case, so it's OK to use static_cast. // 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}; return {vsrc, tpi};
} }
}
// Otherwise we have either a nullptr, an `itype` pointer, or an unknown derived pointer, so // Otherwise we have either a nullptr, an `itype` pointer, or an unknown derived pointer, so
// don't do a cast // don't do a cast
return type_caster_generic::src_and_type(src, cast_type, instance_type); return type_caster_generic::src_and_type(src, cast_type, instance_type);

View File

@ -183,12 +183,13 @@ protected:
#endif #endif
// UB without std::launder, but without breaking ABI and/or // UB without std::launder, but without breaking ABI and/or
// a significant refactoring it's "impossible" to solve. // a significant refactoring it's "impossible" to solve.
if (!std::is_trivially_destructible<capture>::value) if (!std::is_trivially_destructible<capture>::value) {
rec->free_data = [](function_record *r) { rec->free_data = [](function_record *r) {
auto data = PYBIND11_STD_LAUNDER((capture *) &r->data); auto data = PYBIND11_STD_LAUNDER((capture *) &r->data);
(void) data; (void) data;
data->~capture(); data->~capture();
}; };
}
#if defined(__GNUG__) && !PYBIND11_HAS_STD_LAUNDER && !defined(__INTEL_COMPILER) #if defined(__GNUG__) && !PYBIND11_HAS_STD_LAUNDER && !defined(__INTEL_COMPILER)
# pragma GCC diagnostic pop # pragma GCC diagnostic pop
#endif #endif