Skip to content

Commit dc9803c

Browse files
authored
Add missing clang-tidy fixes (#3715)
1 parent 7f97581 commit dc9803c

File tree

6 files changed

+40
-24
lines changed

6 files changed

+40
-24
lines changed

include/pybind11/attr.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,16 @@ template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> {
445445
if (!a.value) {
446446
#if !defined(NDEBUG)
447447
std::string descr("'");
448-
if (a.name) descr += std::string(a.name) + ": ";
448+
if (a.name) {
449+
descr += std::string(a.name) + ": ";
450+
}
449451
descr += a.type + "'";
450452
if (r->is_method) {
451-
if (r->name)
453+
if (r->name) {
452454
descr += " in method '" + (std::string) str(r->scope) + "." + (std::string) r->name + "'";
453-
else
455+
} else {
454456
descr += " in method of '" + (std::string) str(r->scope) + "'";
457+
}
455458
} else if (r->name) {
456459
descr += " in function '" + (std::string) r->name + "'";
457460
}

include/pybind11/cast.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,11 @@ template <template<typename...> class Tuple, typename... Ts> class tuple_caster
628628
return false;
629629
}
630630
#else
631-
for (bool r : {std::get<Is>(subcasters).load(seq[Is], convert)...})
632-
if (!r)
631+
for (bool r : {std::get<Is>(subcasters).load(seq[Is], convert)...}) {
632+
if (!r) {
633633
return false;
634+
}
635+
}
634636
#endif
635637
return true;
636638
}

include/pybind11/detail/internals.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ struct type_hash {
118118
size_t operator()(const std::type_index &t) const {
119119
size_t hash = 5381;
120120
const char *ptr = t.name();
121-
while (auto c = static_cast<unsigned char>(*ptr++))
121+
while (auto c = static_cast<unsigned char>(*ptr++)) {
122122
hash = (hash * 33) ^ c;
123+
}
123124
return hash;
124125
}
125126
};
@@ -388,7 +389,9 @@ inline void translate_exception(std::exception_ptr p) {
388389
#if !defined(__GLIBCXX__)
389390
inline void translate_local_exception(std::exception_ptr p) {
390391
try {
391-
if (p) std::rethrow_exception(p);
392+
if (p) {
393+
std::rethrow_exception(p);
394+
}
392395
} catch (error_already_set &e) { e.restore(); return;
393396
} catch (const builtin_exception &e) { e.set_error(); return;
394397
}

include/pybind11/gil.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ class gil_scoped_acquire {
6565
if (!tstate) {
6666
tstate = PyThreadState_New(internals.istate);
6767
#if !defined(NDEBUG)
68-
if (!tstate)
69-
pybind11_fail("scoped_acquire: could not create thread state!");
70-
#endif
68+
if (!tstate) {
69+
pybind11_fail("scoped_acquire: could not create thread state!");
70+
}
71+
#endif
7172
tstate->gilstate_counter = 0;
7273
PYBIND11_TLS_REPLACE_VALUE(internals.tstate, tstate);
7374
} else {
@@ -88,16 +89,19 @@ class gil_scoped_acquire {
8889
PYBIND11_NOINLINE void dec_ref() {
8990
--tstate->gilstate_counter;
9091
#if !defined(NDEBUG)
91-
if (detail::get_thread_state_unchecked() != tstate)
92-
pybind11_fail("scoped_acquire::dec_ref(): thread state must be current!");
93-
if (tstate->gilstate_counter < 0)
94-
pybind11_fail("scoped_acquire::dec_ref(): reference count underflow!");
95-
#endif
92+
if (detail::get_thread_state_unchecked() != tstate) {
93+
pybind11_fail("scoped_acquire::dec_ref(): thread state must be current!");
94+
}
95+
if (tstate->gilstate_counter < 0) {
96+
pybind11_fail("scoped_acquire::dec_ref(): reference count underflow!");
97+
}
98+
#endif
9699
if (tstate->gilstate_counter == 0) {
97100
#if !defined(NDEBUG)
98-
if (!release)
99-
pybind11_fail("scoped_acquire::dec_ref(): internal error!");
100-
#endif
101+
if (!release) {
102+
pybind11_fail("scoped_acquire::dec_ref(): internal error!");
103+
}
104+
#endif
101105
PyThreadState_Clear(tstate);
102106
if (active) {
103107
PyThreadState_DeleteCurrent();

include/pybind11/pybind11.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,9 +873,10 @@ class cpp_function : public function {
873873
// 5. Put everything in a vector. Not technically step 5, we've been building it
874874
// in `call.args` all along.
875875
#if !defined(NDEBUG)
876-
if (call.args.size() != func.nargs || call.args_convert.size() != func.nargs)
876+
if (call.args.size() != func.nargs || call.args_convert.size() != func.nargs) {
877877
pybind11_fail("Internal error: function call dispatcher inserted wrong number of arguments!");
878-
#endif
878+
}
879+
#endif
879880

880881
std::vector<bool> second_pass_convert;
881882
if (overloaded) {
@@ -2527,8 +2528,9 @@ inline function get_type_override(const void *this_ptr, const type_info *this_ty
25272528
PyFrame_FastToLocals(frame);
25282529
PyObject *self_caller = dict_getitem(
25292530
frame->f_locals, PyTuple_GET_ITEM(frame->f_code->co_varnames, 0));
2530-
if (self_caller == self.ptr())
2531+
if (self_caller == self.ptr()) {
25312532
return function();
2533+
}
25322534
}
25332535
#endif
25342536

tests/test_cmake_build/embed.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ PYBIND11_EMBEDDED_MODULE(test_cmake_build, m) {
66
}
77

88
int main(int argc, char *argv[]) {
9-
if (argc != 2)
9+
if (argc != 2) {
1010
throw std::runtime_error("Expected test.py file as the first argument");
11-
auto test_py_file = argv[1];
11+
}
12+
auto *test_py_file = argv[1];
1213

1314
py::scoped_interpreter guard{};
1415

1516
auto m = py::module_::import("test_cmake_build");
16-
if (m.attr("add")(1, 2).cast<int>() != 3)
17+
if (m.attr("add")(1, 2).cast<int>() != 3) {
1718
throw std::runtime_error("embed.cpp failed");
19+
}
1820

1921
py::module_::import("sys").attr("argv") = py::make_tuple("test.py", "embed.cpp");
2022
py::eval_file(test_py_file, py::globals());

0 commit comments

Comments
 (0)