Skip to content

Commit dfbd49b

Browse files
committed
chore: bump maximum clang
Signed-off-by: Henry Schreiner <[email protected]>
1 parent d7769de commit dfbd49b

18 files changed

+56
-36
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 --preset tidy
5852

5953
- name: Embedded
60-
run: cmake --build build -t cpptest -j 2 -- --keep-going
54+
run: cmake --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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ class tuple_caster {
818818
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(src, policy, parent);
819819
PYBIND11_WORKAROUND_INCORRECT_GCC_UNUSED_BUT_SET_PARAMETER(policy, parent);
820820
std::array<object, size> entries{{reinterpret_steal<object>(
821-
make_caster<Ts>::cast(std::get<Is>(std::forward<T>(src)), policy, parent))...}};
821+
make_caster<Ts>::cast(std::get<Is>(src), policy, parent))...}};
822822
for (const auto &entry : entries) {
823823
if (!entry) {
824824
return handle();

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,

include/pybind11/pytypes.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ using is_pyobject = std::is_base_of<pyobject_tag, remove_reference_t<T>>;
8181
\endrst */
8282
template <typename Derived>
8383
class object_api : public pyobject_tag {
84+
object_api() = default;
8485
const Derived &derived() const { return static_cast<const Derived &>(*this); }
86+
friend Derived;
8587

8688
public:
8789
/** \rst
@@ -276,7 +278,7 @@ class handle : public detail::object_api<handle> {
276278
inc_ref_counter(1);
277279
#endif
278280
#ifdef PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
279-
if (m_ptr != nullptr && !PyGILState_Check()) {
281+
if (m_ptr != nullptr && PyGILState_Check() == 0) {
280282
throw_gilstate_error("pybind11::handle::inc_ref()");
281283
}
282284
#endif
@@ -291,7 +293,7 @@ class handle : public detail::object_api<handle> {
291293
\endrst */
292294
const handle &dec_ref() const & {
293295
#ifdef PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
294-
if (m_ptr != nullptr && !PyGILState_Check()) {
296+
if (m_ptr != nullptr && PyGILState_Check() == 0) {
295297
throw_gilstate_error("pybind11::handle::dec_ref()");
296298
}
297299
#endif

include/pybind11/stl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ struct set_caster {
178178
return true;
179179
}
180180

181-
bool convert_anyset(anyset s, bool convert) {
181+
bool convert_anyset(const anyset &s, bool convert) {
182182
value.clear();
183183
reserve_maybe(s, &value);
184184
return convert_iterable(s, convert);

tests/pure_cpp/smart_holder_poc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
1010
PYBIND11_NAMESPACE_BEGIN(memory)
1111
PYBIND11_NAMESPACE_BEGIN(smart_holder_poc) // Proof-of-Concept implementations.
1212

13+
// NOLINTNEXTLINE(bugprone-incorrect-enable-shared-from-this)
1314
struct PrivateESFT : private std::enable_shared_from_this<PrivateESFT> {};
1415
static_assert(!type_has_shared_from_this(static_cast<PrivateESFT *>(nullptr)),
1516
"should detect inaccessible base");

tests/test_class_sh_basic.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ const std::unique_ptr<atyp> &rtrn_unique_ptr_cref(const std::string &mtxt) {
130130
}
131131

132132
const std::unique_ptr<atyp> &unique_ptr_cref_roundtrip(const std::unique_ptr<atyp> &obj) {
133-
return obj;
133+
// This is passed in, so it can't be given a temporary
134+
return obj; // NOLINT(bugprone-return-const-ref-from-parameter)
134135
}
135136

136137
struct SharedPtrStash {

tests/test_copy_move.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ template <typename derived>
1919
struct empty {
2020
static const derived &get_one() { return instance_; }
2121
static derived instance_;
22+
23+
private:
24+
empty() = default;
25+
friend derived;
2226
};
2327

2428
struct lacking_copy_ctor : public empty<lacking_copy_ctor> {

tests/test_numpy_dtypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ py::array_t<S, 0> create_recarray(size_t n) {
176176
}
177177

178178
template <typename S>
179-
py::list print_recarray(py::array_t<S, 0> arr) {
179+
py::list print_recarray(const py::array_t<S, 0> &arr) {
180180
const auto req = arr.request();
181181
auto *const ptr = static_cast<S *>(req.ptr);
182182
auto l = py::list();
@@ -301,7 +301,7 @@ py::list test_dtype_ctors() {
301301
}
302302

303303
template <typename T>
304-
py::array_t<T> dispatch_array_increment(py::array_t<T> arr) {
304+
py::array_t<T> dispatch_array_increment(const py::array_t<T> &arr) {
305305
py::array_t<T> res(arr.shape(0));
306306
for (py::ssize_t i = 0; i < arr.shape(0); ++i) {
307307
res.mutable_at(i) = T(arr.at(i) + 1);

tests/test_sequences_and_iterators.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableInt>)
9090
PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableIntPair>)
9191

9292
template <typename PythonType>
93-
py::list test_random_access_iterator(PythonType x) {
93+
py::list test_random_access_iterator(const PythonType &x) {
9494
if (x.size() < 5) {
9595
throw py::value_error("Please provide at least 5 elements for testing.");
9696
}

tests/test_smart_ptr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ TEST_SUBMODULE(smart_ptr, m) {
540540
return list;
541541
});
542542

543+
// NOLINTNEXTLINE(bugprone-incorrect-enable-shared-from-this)
543544
class PrivateESFT : /* implicit private */ std::enable_shared_from_this<PrivateESFT> {};
544545
struct ContainerUsingPrivateESFT {
545546
std::shared_ptr<PrivateESFT> ptr;

0 commit comments

Comments
 (0)