Skip to content

Commit 7f23e9f

Browse files
authored
chore: update clang-tidy to 15 (#4387)
* chore: update clang-tidy to 15 * Add git * Add NOLINTNEXTLINE for assignment in if * Update CONTRIBUTING.md * Add NOLINTNEXTLINE where needed * Add one more NOLINTNEXTLINE * stl_bind: make more readable * Another missing NOLINTNEXTLINE * Match style elsewhere * Apply reviewer suggestion. Mark false positive
1 parent 0694ec6 commit 7f23e9f

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

.github/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ directory inside your pybind11 git clone. Files will be modified in place,
235235
so you can use git to monitor the changes.
236236

237237
```bash
238-
docker run --rm -v $PWD:/mounted_pybind11 -it silkeh/clang:13
239-
apt-get update && apt-get install -y python3-dev python3-pytest
238+
docker run --rm -v $PWD:/mounted_pybind11 -it silkeh/clang:15-bullseye
239+
apt-get update && apt-get install -y git python3-dev python3-pytest
240240
cmake -S /mounted_pybind11/ -B build -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);--use-color" -DDOWNLOAD_EIGEN=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_STANDARD=17
241241
cmake --build build -j 2
242242
```

.github/workflows/format.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ jobs:
3838
# in .github/CONTRIBUTING.md and update as needed.
3939
name: Clang-Tidy
4040
runs-on: ubuntu-latest
41-
container: silkeh/clang:13
41+
container: silkeh/clang:15-bullseye
4242
steps:
4343
- uses: actions/checkout@v3
4444

4545
- name: Install requirements
46-
run: apt-get update && apt-get install -y python3-dev python3-pytest
46+
run: apt-get update && apt-get install -y git python3-dev python3-pytest
4747

4848
- name: Configure
4949
run: >

include/pybind11/detail/internals.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,14 @@ PYBIND11_NOINLINE internals &get_internals() {
469469
#if defined(WITH_THREAD)
470470

471471
PyThreadState *tstate = PyThreadState_Get();
472+
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
472473
if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->tstate)) {
473474
pybind11_fail("get_internals: could not successfully initialize the tstate TSS key!");
474475
}
475476
PYBIND11_TLS_REPLACE_VALUE(internals_ptr->tstate, tstate);
476477

477478
# if PYBIND11_INTERNALS_VERSION > 4
479+
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
478480
if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->loader_life_support_tls_key)) {
479481
pybind11_fail("get_internals: could not successfully initialize the "
480482
"loader_life_support TSS key!");
@@ -514,6 +516,7 @@ struct local_internals {
514516
struct shared_loader_life_support_data {
515517
PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key)
516518
shared_loader_life_support_data() {
519+
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
517520
if (!PYBIND11_TLS_KEY_CREATE(loader_life_support_tls_key)) {
518521
pybind11_fail("local_internals: could not successfully initialize the "
519522
"loader_life_support TLS key!");

include/pybind11/stl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ struct optional_caster {
316316
if (!std::is_lvalue_reference<T>::value) {
317317
policy = return_value_policy_override<Value>::policy(policy);
318318
}
319+
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
319320
return value_conv::cast(*std::forward<T>(src), policy, parent);
320321
}
321322

include/pybind11/stl_bind.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,17 @@ void vector_accessor(enable_if_t<vector_needs_copy<Vector>::value, Class_> &cl)
355355
using DiffType = typename Vector::difference_type;
356356
using ItType = typename Vector::iterator;
357357
cl.def("__getitem__", [](const Vector &v, DiffType i) -> T {
358-
if (i < 0 && (i += v.size()) < 0) {
359-
throw index_error();
358+
if (i < 0) {
359+
i += v.size();
360+
if (i < 0) {
361+
throw index_error();
362+
}
360363
}
361-
if ((SizeType) i >= v.size()) {
364+
auto i_st = static_cast<SizeType>(i);
365+
if (i_st >= v.size()) {
362366
throw index_error();
363367
}
364-
return v[(SizeType) i];
368+
return v[i_st];
365369
});
366370

367371
cl.def(

0 commit comments

Comments
 (0)