Commit 7f23e9f3 by Aaron Gokaslan Committed by GitHub

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
parent 0694ec6a
...@@ -235,8 +235,8 @@ directory inside your pybind11 git clone. Files will be modified in place, ...@@ -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. so you can use git to monitor the changes.
```bash ```bash
docker run --rm -v $PWD:/mounted_pybind11 -it silkeh/clang:13 docker run --rm -v $PWD:/mounted_pybind11 -it silkeh/clang:15-bullseye
apt-get update && apt-get install -y python3-dev python3-pytest 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 -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 cmake --build build -j 2
``` ```
......
...@@ -38,12 +38,12 @@ jobs: ...@@ -38,12 +38,12 @@ jobs:
# in .github/CONTRIBUTING.md and update as needed. # in .github/CONTRIBUTING.md and update as needed.
name: Clang-Tidy name: Clang-Tidy
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: silkeh/clang:13 container: silkeh/clang:15-bullseye
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Install requirements - 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 - name: Configure
run: > run: >
......
...@@ -469,12 +469,14 @@ PYBIND11_NOINLINE internals &get_internals() { ...@@ -469,12 +469,14 @@ PYBIND11_NOINLINE internals &get_internals() {
#if defined(WITH_THREAD) #if defined(WITH_THREAD)
PyThreadState *tstate = PyThreadState_Get(); PyThreadState *tstate = PyThreadState_Get();
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->tstate)) { if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->tstate)) {
pybind11_fail("get_internals: could not successfully initialize the tstate TSS key!"); pybind11_fail("get_internals: could not successfully initialize the tstate TSS key!");
} }
PYBIND11_TLS_REPLACE_VALUE(internals_ptr->tstate, tstate); PYBIND11_TLS_REPLACE_VALUE(internals_ptr->tstate, tstate);
# if PYBIND11_INTERNALS_VERSION > 4 # if PYBIND11_INTERNALS_VERSION > 4
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->loader_life_support_tls_key)) { if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->loader_life_support_tls_key)) {
pybind11_fail("get_internals: could not successfully initialize the " pybind11_fail("get_internals: could not successfully initialize the "
"loader_life_support TSS key!"); "loader_life_support TSS key!");
...@@ -514,6 +516,7 @@ struct local_internals { ...@@ -514,6 +516,7 @@ struct local_internals {
struct shared_loader_life_support_data { struct shared_loader_life_support_data {
PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key) PYBIND11_TLS_KEY_INIT(loader_life_support_tls_key)
shared_loader_life_support_data() { shared_loader_life_support_data() {
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
if (!PYBIND11_TLS_KEY_CREATE(loader_life_support_tls_key)) { if (!PYBIND11_TLS_KEY_CREATE(loader_life_support_tls_key)) {
pybind11_fail("local_internals: could not successfully initialize the " pybind11_fail("local_internals: could not successfully initialize the "
"loader_life_support TLS key!"); "loader_life_support TLS key!");
......
...@@ -316,6 +316,7 @@ struct optional_caster { ...@@ -316,6 +316,7 @@ struct optional_caster {
if (!std::is_lvalue_reference<T>::value) { if (!std::is_lvalue_reference<T>::value) {
policy = return_value_policy_override<Value>::policy(policy); policy = return_value_policy_override<Value>::policy(policy);
} }
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
return value_conv::cast(*std::forward<T>(src), policy, parent); return value_conv::cast(*std::forward<T>(src), policy, parent);
} }
......
...@@ -355,13 +355,17 @@ void vector_accessor(enable_if_t<vector_needs_copy<Vector>::value, Class_> &cl) ...@@ -355,13 +355,17 @@ void vector_accessor(enable_if_t<vector_needs_copy<Vector>::value, Class_> &cl)
using DiffType = typename Vector::difference_type; using DiffType = typename Vector::difference_type;
using ItType = typename Vector::iterator; using ItType = typename Vector::iterator;
cl.def("__getitem__", [](const Vector &v, DiffType i) -> T { cl.def("__getitem__", [](const Vector &v, DiffType i) -> T {
if (i < 0 && (i += v.size()) < 0) { if (i < 0) {
throw index_error(); 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(); throw index_error();
} }
return v[(SizeType) i]; return v[i_st];
}); });
cl.def( cl.def(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment