Skip to content

Commit 8581584

Browse files
committed
Manual fix-ups in preparation for clang-tidy readability-braces-around-statements.
Informed by experiments under PR #3698.
1 parent af056b6 commit 8581584

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

include/pybind11/cast.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -915,14 +915,15 @@ template <> inline void handle::cast() const { return; }
915915

916916
template <typename T>
917917
detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) {
918-
if (obj.ref_count() > 1)
918+
if (obj.ref_count() > 1) {
919919
#if defined(NDEBUG)
920920
throw cast_error("Unable to cast Python instance to C++ rvalue: instance has multiple references"
921921
" (compile in debug mode for details)");
922922
#else
923923
throw cast_error("Unable to move from Python " + (std::string) str(type::handle_of(obj)) +
924924
" instance to C++ " + type_id<T>() + " instance: instance has multiple references");
925925
#endif
926+
}
926927

927928
// Move into a temporary and return that, because the reference may be a local value of `conv`
928929
T ret = std::move(detail::load_type<T>(obj).operator T&());
@@ -1192,12 +1193,15 @@ class argument_loader {
11921193
template <size_t... Is>
11931194
bool load_impl_sequence(function_call &call, index_sequence<Is...>) {
11941195
#ifdef __cpp_fold_expressions
1195-
if ((... || !std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is])))
1196+
if ((... || !std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is]))) {
11961197
return false;
1198+
}
11971199
#else
1198-
for (bool r : {std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is])...})
1199-
if (!r)
1200+
for (bool r : {std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is])...}) {
1201+
if (!r) {
12001202
return false;
1203+
}
1204+
}
12011205
#endif
12021206
return true;
12031207
}
@@ -1286,13 +1290,13 @@ class unpacking_collector {
12861290
}
12871291

12881292
void process(list &/*args_list*/, arg_v a) {
1289-
if (!a.name)
1293+
if (!a.name) {
12901294
#if defined(NDEBUG)
12911295
nameless_argument_error();
12921296
#else
12931297
nameless_argument_error(a.type);
12941298
#endif
1295-
1299+
}
12961300
if (m_kwargs.contains(a.name)) {
12971301
#if defined(NDEBUG)
12981302
multiple_values_error();

include/pybind11/detail/init.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,13 @@ struct factory<CFunc, AFunc, CReturn(CArgs...), AReturn(AArgs...)> {
276276
cl.def("__init__", [class_func, alias_func]
277277
#endif
278278
(value_and_holder &v_h, CArgs... args) {
279-
if (Py_TYPE(v_h.inst) == v_h.type->type)
279+
if (Py_TYPE(v_h.inst) == v_h.type->type) {
280280
// If the instance type equals the registered type we don't have inheritance, so
281281
// don't need the alias and can construct using the class function:
282282
construct<Class>(v_h, class_func(std::forward<CArgs>(args)...), false);
283-
else
283+
} else {
284284
construct<Class>(v_h, alias_func(std::forward<CArgs>(args)...), true);
285+
}
285286
}, is_new_style_constructor(), extra...);
286287
}
287288
};

include/pybind11/detail/type_caster_base.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,12 +625,15 @@ class type_caster_generic {
625625
vptr = type->operator_new(type->type_size);
626626
} else {
627627
#if defined(__cpp_aligned_new) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
628-
if (type->type_align > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
628+
if (type->type_align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
629629
vptr = ::operator new(type->type_size,
630630
std::align_val_t(type->type_align));
631-
else
631+
} else {
632+
vptr = ::operator new(type->type_size);
633+
}
634+
#else
635+
vptr = ::operator new(type->type_size);
632636
#endif
633-
vptr = ::operator new(type->type_size);
634637
}
635638
}
636639
value = vptr;
@@ -778,8 +781,9 @@ class type_caster_generic {
778781
// with .second = nullptr. (p.first = nullptr is not an error: it becomes None).
779782
PYBIND11_NOINLINE static std::pair<const void *, const type_info *> src_and_type(
780783
const void *src, const std::type_info &cast_type, const std::type_info *rtti_type = nullptr) {
781-
if (auto *tpi = get_type_info(cast_type))
784+
if (auto *tpi = get_type_info(cast_type)) {
782785
return {src, const_cast<const type_info *>(tpi)};
786+
}
783787

784788
// Not found, set error:
785789
std::string tname = rtti_type ? rtti_type->name() : cast_type.name();
@@ -928,8 +932,9 @@ template <typename type> class type_caster_base : public type_caster_generic {
928932
// except via a user-provided specialization of polymorphic_type_hook,
929933
// and the user has promised that no this-pointer adjustment is
930934
// required in that case, so it's OK to use static_cast.
931-
if (const auto *tpi = get_type_info(*instance_type))
935+
if (const auto *tpi = get_type_info(*instance_type)) {
932936
return {vsrc, tpi};
937+
}
933938
}
934939
// Otherwise we have either a nullptr, an `itype` pointer, or an unknown derived pointer, so
935940
// don't do a cast

include/pybind11/pybind11.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,13 @@ class cpp_function : public function {
183183
#endif
184184
// UB without std::launder, but without breaking ABI and/or
185185
// a significant refactoring it's "impossible" to solve.
186-
if (!std::is_trivially_destructible<capture>::value)
186+
if (!std::is_trivially_destructible<capture>::value) {
187187
rec->free_data = [](function_record *r) {
188188
auto data = PYBIND11_STD_LAUNDER((capture *) &r->data);
189189
(void) data;
190190
data->~capture();
191191
};
192+
}
192193
#if defined(__GNUG__) && !PYBIND11_HAS_STD_LAUNDER && !defined(__INTEL_COMPILER)
193194
# pragma GCC diagnostic pop
194195
#endif

0 commit comments

Comments
 (0)