Skip to content

Commit ddbc74c

Browse files
committed
Adding .clang-tidy readability-braces-around-statements option.
clang-tidy automatic changes. NO manual changes.
1 parent 8581584 commit ddbc74c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1363
-678
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ modernize-use-override,
3131
modernize-use-using,
3232
*performance*,
3333
readability-avoid-const-params-in-decls,
34+
readability-braces-around-statements,
3435
readability-const-return-type,
3536
readability-container-size-empty,
3637
readability-delete-null-pointer,

include/pybind11/attr.h

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,13 @@ struct type_record {
330330

331331
bases.append((PyObject *) base_info->type);
332332

333-
if (base_info->type->tp_dictoffset != 0)
333+
if (base_info->type->tp_dictoffset != 0) {
334334
dynamic_attr = true;
335+
}
335336

336-
if (caster)
337+
if (caster) {
337338
base_info->implicit_casts.emplace_back(type, caster);
339+
}
338340
}
339341
};
340342

@@ -410,13 +412,16 @@ template <> struct process_attribute<is_new_style_constructor> : process_attribu
410412
};
411413

412414
inline void check_kw_only_arg(const arg &a, function_record *r) {
413-
if (r->args.size() > r->nargs_pos && (!a.name || a.name[0] == '\0'))
414-
pybind11_fail("arg(): cannot specify an unnamed argument after a kw_only() annotation or args() argument");
415+
if (r->args.size() > r->nargs_pos && (!a.name || a.name[0] == '\0')) {
416+
pybind11_fail("arg(): cannot specify an unnamed argument after a kw_only() annotation or "
417+
"args() argument");
418+
}
415419
}
416420

417421
inline void append_self_arg_if_needed(function_record *r) {
418-
if (r->is_method && r->args.empty())
419-
r->args.emplace_back("self", nullptr, handle(), /*convert=*/ true, /*none=*/ false);
422+
if (r->is_method && r->args.empty()) {
423+
r->args.emplace_back("self", nullptr, handle(), /*convert=*/true, /*none=*/false);
424+
}
420425
}
421426

422427
/// Process a keyword argument attribute (*without* a default value)
@@ -432,8 +437,10 @@ template <> struct process_attribute<arg> : process_attribute_default<arg> {
432437
/// Process a keyword argument attribute (*with* a default value)
433438
template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> {
434439
static void init(const arg_v &a, function_record *r) {
435-
if (r->is_method && r->args.empty())
436-
r->args.emplace_back("self", /*descr=*/ nullptr, /*parent=*/ handle(), /*convert=*/ true, /*none=*/ false);
440+
if (r->is_method && r->args.empty()) {
441+
r->args.emplace_back(
442+
"self", /*descr=*/nullptr, /*parent=*/handle(), /*convert=*/true, /*none=*/false);
443+
}
437444

438445
if (!a.value) {
439446
#if !defined(NDEBUG)
@@ -466,8 +473,10 @@ template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> {
466473
template <> struct process_attribute<kw_only> : process_attribute_default<kw_only> {
467474
static void init(const kw_only &, function_record *r) {
468475
append_self_arg_if_needed(r);
469-
if (r->has_args && r->nargs_pos != static_cast<std::uint16_t>(r->args.size()))
470-
pybind11_fail("Mismatched args() and kw_only(): they must occur at the same relative argument location (or omit kw_only() entirely)");
476+
if (r->has_args && r->nargs_pos != static_cast<std::uint16_t>(r->args.size())) {
477+
pybind11_fail("Mismatched args() and kw_only(): they must occur at the same relative "
478+
"argument location (or omit kw_only() entirely)");
479+
}
471480
r->nargs_pos = static_cast<std::uint16_t>(r->args.size());
472481
}
473482
};
@@ -477,8 +486,9 @@ template <> struct process_attribute<pos_only> : process_attribute_default<pos_o
477486
static void init(const pos_only &, function_record *r) {
478487
append_self_arg_if_needed(r);
479488
r->nargs_pos_only = static_cast<std::uint16_t>(r->args.size());
480-
if (r->nargs_pos_only > r->nargs_pos)
489+
if (r->nargs_pos_only > r->nargs_pos) {
481490
pybind11_fail("pos_only(): cannot follow a py::args() argument");
491+
}
482492
// It also can't follow a kw_only, but a static_assert in pybind11.h checks that
483493
}
484494
};

include/pybind11/buffer_info.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@ PYBIND11_NAMESPACE_BEGIN(detail)
1919
inline std::vector<ssize_t> c_strides(const std::vector<ssize_t> &shape, ssize_t itemsize) {
2020
auto ndim = shape.size();
2121
std::vector<ssize_t> strides(ndim, itemsize);
22-
if (ndim > 0)
23-
for (size_t i = ndim - 1; i > 0; --i)
22+
if (ndim > 0) {
23+
for (size_t i = ndim - 1; i > 0; --i) {
2424
strides[i - 1] = strides[i] * shape[i];
25+
}
26+
}
2527
return strides;
2628
}
2729

2830
// F-style strides; default when constructing an array_t with `ExtraFlags & f_style`
2931
inline std::vector<ssize_t> f_strides(const std::vector<ssize_t> &shape, ssize_t itemsize) {
3032
auto ndim = shape.size();
3133
std::vector<ssize_t> strides(ndim, itemsize);
32-
for (size_t i = 1; i < ndim; ++i)
34+
for (size_t i = 1; i < ndim; ++i) {
3335
strides[i] = strides[i - 1] * shape[i - 1];
36+
}
3437
return strides;
3538
}
3639

@@ -53,10 +56,12 @@ struct buffer_info {
5356
detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
5457
: ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim),
5558
shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) {
56-
if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size())
59+
if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size()) {
5760
pybind11_fail("buffer_info: ndim doesn't match shape and/or strides length");
58-
for (size_t i = 0; i < (size_t) ndim; ++i)
61+
}
62+
for (size_t i = 0; i < (size_t) ndim; ++i) {
5963
size *= shape[i];
64+
}
6065
}
6166

6267
template <typename T>

0 commit comments

Comments
 (0)