Skip to content

Commit 1dd85ef

Browse files
authored
chore: bump maximum clang tested to 20 (#5692)
1 parent 9d06626 commit 1dd85ef

18 files changed

+57
-35
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Checks: |
6363
-bugprone-reserved-identifier,
6464
-bugprone-unused-raii,
6565
-performance-enum-size,
66+
-performance-inefficient-string-concatenation,
6667
6768
CheckOptions:
6869
- key: modernize-use-equals-default.IgnoreMacros

.github/CONTRIBUTING.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,17 @@ of the pybind11 repo.
262262
more complex to run, compared to `clang-format`, but support for `clang-tidy`
263263
is built into the pybind11 CMake configuration. To run `clang-tidy`, the
264264
following recipe should work. Run the `docker` command from the top-level
265-
directory inside your pybind11 git clone. Files will be modified in place,
266-
so you can use git to monitor the changes.
265+
directory inside your pybind11 git clone.
267266

268267
```bash
269-
docker run --rm -v $PWD:/mounted_pybind11 -it silkeh/clang:15-bullseye
270-
apt-get update && apt-get install -y git python3-dev python3-pytest
271-
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
272-
cmake --build build -j 2
268+
docker run --rm -v $PWD:/pybind11 -w /pybind11 -it silkeh/clang:20
269+
apt-get update && apt-get install -y git python3-dev python3-pytest ninja-build
270+
cmake --preset tidy
271+
cmake --build --preset tidy
273272
```
274273

275-
You can add `--fix` to the options list if you want.
274+
You can add `--fix` to the options list in the preset if you want to apply fixes
275+
(remember `-j1` to run only one thread).
276276

277277
### Include what you use
278278

@@ -281,7 +281,7 @@ macOS), then run:
281281

282282
```bash
283283
cmake -S . -B build-iwyu -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=$(which include-what-you-use)
284-
cmake --build build
284+
cmake --build build-iwyu
285285
```
286286

287287
The report is sent to stderr; you can pipe it into a file if you wish.

.github/workflows/format.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,17 @@ jobs:
3838
# in .github/CONTRIBUTING.md and update as needed.
3939
name: Clang-Tidy
4040
runs-on: ubuntu-latest
41-
container: silkeh/clang:18-bookworm
41+
container: silkeh/clang:20
4242
steps:
4343
- uses: actions/checkout@v4
4444

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

4848
- name: Configure
49-
run: >
50-
cmake -S . -B build
51-
-DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);--use-color;--warnings-as-errors=*"
52-
-DDOWNLOAD_EIGEN=ON
53-
-DDOWNLOAD_CATCH=ON
54-
-DCMAKE_CXX_STANDARD=17
55-
49+
run: cmake --preset tidy
5650
- name: Build
57-
run: cmake --build build -j 2 -- --keep-going
51+
run: cmake --build --preset tidy
5852

5953
- name: Embedded
60-
run: cmake --build build -t cpptest -j 2 -- --keep-going
54+
run: cmake --build --preset tidy -t cpptest

CMakePresets.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@
2525
"displayName": "Venv",
2626
"inherits": "default",
2727
"cacheVariables": {
28-
"CMAKE_BUILD_TYPE": "Debug",
29-
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
30-
"DOWNLOAD_CATCH": true,
31-
"DOWNLOAD_EIGEN": true,
3228
"PYBIND11_CREATE_WITH_UV": "python3",
33-
"PYBIND11_FINDPYTHON": "NEW",
34-
"PYBIND11_WERROR": true,
3529
"Python_ROOT_DIR": ".venv"
3630
}
31+
},
32+
{
33+
"name": "tidy",
34+
"displayName": "Clang-tidy",
35+
"inherits": "default",
36+
"binaryDir": "build-tidy",
37+
"cacheVariables": {
38+
"CMAKE_CXX_CLANG_TIDY": "clang-tidy;--use-color;--warnings-as-errors=*",
39+
"CMAKE_CXX_STANDARD": "17"
40+
}
3741
}
3842
],
3943
"buildPresets": [
@@ -47,6 +51,12 @@
4751
"displayName": "Venv Build",
4852
"configurePreset": "venv"
4953
},
54+
{
55+
"name": "tidy",
56+
"displayName": "Clang-tidy Build",
57+
"configurePreset": "tidy",
58+
"nativeToolOptions": ["-k0"]
59+
},
5060
{
5161
"name": "tests",
5262
"displayName": "Tests (for workflow)",

include/pybind11/cast.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,9 @@ class tuple_caster {
817817
cast_impl(T &&src, return_value_policy policy, handle parent, index_sequence<Is...>) {
818818
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(src, policy, parent);
819819
PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(policy, parent);
820+
820821
std::array<object, size> entries{{reinterpret_steal<object>(
822+
// NOLINTNEXTLINE(bugprone-use-after-move)
821823
make_caster<Ts>::cast(std::get<Is>(std::forward<T>(src)), policy, parent))...}};
822824
for (const auto &entry : entries) {
823825
if (!entry) {

include/pybind11/chrono.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class duration_caster {
6363
get_duration(const std::chrono::duration<rep, period> &src) {
6464
return src;
6565
}
66+
static const std::chrono::duration<rep, period> &
67+
get_duration(const std::chrono::duration<rep, period> &&)
68+
= delete;
6669

6770
// If this is a time_point get the time_since_epoch
6871
template <typename Clock>

include/pybind11/detail/init.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ struct constructor {
273273
static void execute(Class &cl, const Extra &...extra) {
274274
cl.def(
275275
"__init__",
276-
[](value_and_holder &v_h, Args... args) {
276+
[](value_and_holder &v_h,
277+
Args... args) { // NOLINT(performance-unnecessary-value-param)
277278
v_h.value_ptr() = construct_or_initialize<Cpp<Class>>(std::forward<Args>(args)...);
278279
},
279280
is_new_style_constructor(),

include/pybind11/detail/struct_smart_holder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ struct smart_holder {
340340
}
341341

342342
template <typename T>
343-
static smart_holder from_shared_ptr(std::shared_ptr<T> shd_ptr) {
343+
static smart_holder from_shared_ptr(const std::shared_ptr<T> &shd_ptr) {
344344
smart_holder hld;
345345
hld.vptr = std::static_pointer_cast<void>(shd_ptr);
346346
hld.vptr_is_external_shared_ptr = true;

include/pybind11/functional.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct func_wrapper_base {
4848
template <typename Return, typename... Args>
4949
struct func_wrapper : func_wrapper_base {
5050
using func_wrapper_base::func_wrapper_base;
51-
Return operator()(Args... args) const {
51+
Return operator()(Args... args) const { // NOLINT(performance-unnecessary-value-param)
5252
gil_scoped_acquire acq;
5353
// casts the returned object as a rvalue to the return type
5454
return hfunc.f(std::forward<Args>(args)...).template cast<Return>();

include/pybind11/pybind11.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,6 +3043,7 @@ template <typename Access,
30433043
typename Sentinel,
30443044
typename ValueType,
30453045
typename... Extra>
3046+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
30463047
iterator make_iterator_impl(Iterator first, Sentinel last, Extra &&...extra) {
30473048
using state = detail::iterator_state<Access, Policy, Iterator, Sentinel, ValueType, Extra...>;
30483049
// TODO: state captures only the types of Extra, not the values
@@ -3082,6 +3083,7 @@ template <return_value_policy Policy = return_value_policy::reference_internal,
30823083
typename Sentinel,
30833084
typename ValueType = typename detail::iterator_access<Iterator>::result_type,
30843085
typename... Extra>
3086+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
30853087
typing::Iterator<ValueType> make_iterator(Iterator first, Sentinel last, Extra &&...extra) {
30863088
return detail::make_iterator_impl<detail::iterator_access<Iterator>,
30873089
Policy,

0 commit comments

Comments
 (0)