mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-21 20:55:11 +00:00
Manual fix-ups in preparation for clang-tidy readability-braces-around-statements.
Informed by experiments under PR #3698.
This commit is contained in:
parent
af056b65d3
commit
8581584e60
@ -915,7 +915,7 @@ 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)");
|
||||
@ -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)) +
|
||||
" 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&());
|
||||
@ -1192,12 +1193,15 @@ private:
|
||||
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;
|
||||
}
|
||||
@ -1286,13 +1290,13 @@ private:
|
||||
}
|
||||
|
||||
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();
|
||||
|
@ -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...);
|
||||
}
|
||||
};
|
||||
|
@ -625,12 +625,15 @@ public:
|
||||
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 @@ public:
|
||||
// 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();
|
||||
@ -928,8 +932,9 @@ public:
|
||||
// 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
|
||||
|
@ -183,12 +183,13 @@ protected:
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user