Skip to content

Commit

Permalink
Manual fix-ups in preparation for clang-tidy readability-braces-aroun…
Browse files Browse the repository at this point in the history
…d-statements.

Informed by experiments under PR #3698.
  • Loading branch information
Ralf W. Grosse-Kunstleve authored and rwgk committed Feb 8, 2022
1 parent af056b6 commit 8581584
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
16 changes: 10 additions & 6 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -915,14 +915,15 @@ template <> inline void handle::cast() const { return; }

template <typename T>
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)
throw cast_error("Unable to cast Python instance to C++ rvalue: instance has multiple references"
" (compile in debug mode for details)");
#else
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");
#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<T>(obj).operator T&());
Expand Down Expand Up @@ -1192,12 +1193,15 @@ class argument_loader {
template <size_t... Is>
bool load_impl_sequence(function_call &call, index_sequence<Is...>) {
#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;
}
#else
for (bool r : {std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is])...})
if (!r)
for (bool r : {std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is])...}) {
if (!r) {
return false;
}
}
#endif
return true;
}
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions include/pybind11/detail/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,13 @@ struct factory<CFunc, AFunc, CReturn(CArgs...), AReturn(AArgs...)> {
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<Class>(v_h, class_func(std::forward<CArgs>(args)...), false);
else
} else {
construct<Class>(v_h, alias_func(std::forward<CArgs>(args)...), true);
}
}, is_new_style_constructor(), extra...);
}
};
Expand Down
15 changes: 10 additions & 5 deletions include/pybind11/detail/type_caster_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<const void *, const type_info *> 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<const type_info *>(tpi)};
}

// Not found, set error:
std::string tname = rtti_type ? rtti_type->name() : cast_type.name();
Expand Down Expand Up @@ -928,8 +932,9 @@ template <typename type> 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
Expand Down
3 changes: 2 additions & 1 deletion include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<capture>::value)
if (!std::is_trivially_destructible<capture>::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
Expand Down

0 comments on commit 8581584

Please sign in to comment.