Skip to content

Commit

Permalink
chore: update clang-tidy to 15 (#4387)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Skylion007 committed Dec 27, 2022
1 parent 0694ec6 commit 7f23e9f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Expand Up @@ -235,8 +235,8 @@ directory inside your pybind11 git clone. Files will be modified in place,
so you can use git to monitor the changes.

```bash
docker run --rm -v $PWD:/mounted_pybind11 -it silkeh/clang:13
apt-get update && apt-get install -y python3-dev python3-pytest
docker run --rm -v $PWD:/mounted_pybind11 -it silkeh/clang:15-bullseye
apt-get update && apt-get install -y git python3-dev python3-pytest
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
cmake --build build -j 2
```
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/format.yml
Expand Up @@ -38,12 +38,12 @@ jobs:
# in .github/CONTRIBUTING.md and update as needed.
name: Clang-Tidy
runs-on: ubuntu-latest
container: silkeh/clang:13
container: silkeh/clang:15-bullseye
steps:
- uses: actions/checkout@v3

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

- name: Configure
run: >
Expand Down
3 changes: 3 additions & 0 deletions include/pybind11/detail/internals.h
Expand Up @@ -469,12 +469,14 @@ PYBIND11_NOINLINE internals &get_internals() {
#if defined(WITH_THREAD)

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

# if PYBIND11_INTERNALS_VERSION > 4
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->loader_life_support_tls_key)) {
pybind11_fail("get_internals: could not successfully initialize the "
"loader_life_support TSS key!");
Expand Down Expand Up @@ -514,6 +516,7 @@ struct local_internals {
struct shared_loader_life_support_data {
PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key)
shared_loader_life_support_data() {
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
if (!PYBIND11_TLS_KEY_CREATE(loader_life_support_tls_key)) {
pybind11_fail("local_internals: could not successfully initialize the "
"loader_life_support TLS key!");
Expand Down
1 change: 1 addition & 0 deletions include/pybind11/stl.h
Expand Up @@ -316,6 +316,7 @@ struct optional_caster {
if (!std::is_lvalue_reference<T>::value) {
policy = return_value_policy_override<Value>::policy(policy);
}
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
return value_conv::cast(*std::forward<T>(src), policy, parent);
}

Expand Down
12 changes: 8 additions & 4 deletions include/pybind11/stl_bind.h
Expand Up @@ -355,13 +355,17 @@ void vector_accessor(enable_if_t<vector_needs_copy<Vector>::value, Class_> &cl)
using DiffType = typename Vector::difference_type;
using ItType = typename Vector::iterator;
cl.def("__getitem__", [](const Vector &v, DiffType i) -> T {
if (i < 0 && (i += v.size()) < 0) {
throw index_error();
if (i < 0) {
i += v.size();
if (i < 0) {
throw index_error();
}
}
if ((SizeType) i >= v.size()) {
auto i_st = static_cast<SizeType>(i);
if (i_st >= v.size()) {
throw index_error();
}
return v[(SizeType) i];
return v[i_st];
});

cl.def(
Expand Down

0 comments on commit 7f23e9f

Please sign in to comment.