Skip to content

Commit e9e8b37

Browse files
committed
* Removing clang-format off-on-off directives.
* Inserting clang-format using the same docker container as used for clang-tidy (silkeh/clang:12). * Removing stray semicolons (discovered by running clang-format v12 followed by tools/check-style.sh). * Manually moving `// NOLINT` and `// NOLINTNEXTLINE` comments so that clang-format does not move them to the wrong places. * Manually reformatting comments related to `static_assert`s so that clang-format does not need two passes. * git diff -U0 --no-color HEAD^ | python3 $HOME/clone/llvm-project/clang/tools/clang-format/clang-format-diff.py -p1 -style=file -i
1 parent b5357d1 commit e9e8b37

16 files changed

+102
-66
lines changed

include/pybind11/attr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ struct metaclass {
6262
handle value;
6363

6464
PYBIND11_DEPRECATED("py::metaclass() is no longer required. It's turned on by default now.")
65-
metaclass() { } // NOLINT(modernize-use-equals-default): breaks MSVC 2015 when adding an attribute
65+
// NOLINTNEXTLINE(modernize-use-equals-default): breaks MSVC 2015 when adding an attribute
66+
metaclass() {}
6667

6768
/// Override pybind11's default metaclass
6869
explicit metaclass(handle value) : value(value) { }

include/pybind11/detail/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ struct nodelete { template <typename T> void operator()(T*) { } };
801801
PYBIND11_NAMESPACE_BEGIN(detail)
802802
template <typename... Args>
803803
struct overload_cast_impl {
804-
constexpr overload_cast_impl() {}; // NOLINT(modernize-use-equals-default): MSVC 2015 needs this
804+
constexpr overload_cast_impl() {} // NOLINT(modernize-use-equals-default): MSVC 2015 needs this
805805

806806
template <typename Return>
807807
constexpr auto operator()(Return (*pf)(Args...)) const noexcept

tests/pybind11_cross_module_tests.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,12 @@ PYBIND11_MODULE(pybind11_cross_module_tests, m) {
104104
m.def("return_self", [](LocalVec *v) { return v; });
105105
m.def("return_copy", [](const LocalVec &v) { return LocalVec(v); });
106106

107-
// Changing this broke things with pygrep. TODO fix
108-
// NOLINTNEXTLINE
109-
class Dog : public pets::Pet { public: Dog(std::string name) : Pet(name) {}; };
107+
class Dog : public pets::Pet {
108+
public:
109+
// Changing this broke things with pygrep. TODO fix
110+
// NOLINTNEXTLINE
111+
Dog(std::string name) : Pet(name) {}
112+
};
110113
py::class_<pets::Pet>(m, "Pet", py::module_local())
111114
.def("name", &pets::Pet::name);
112115
// Binding for local extending class:

tests/test_buffers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ TEST_SUBMODULE(buffers, m) {
155155
py::format_descriptor<int32_t>::format(), 1);
156156
}
157157

158-
ConstBuffer() : value(new int32_t{0}) { };
158+
ConstBuffer() : value(new int32_t{0}) {}
159159
};
160160
py::class_<ConstBuffer>(m, "ConstBuffer", py::buffer_protocol())
161161
.def(py::init<>())

tests/test_builtin_casters.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,13 @@ TEST_SUBMODULE(builtin_casters, m) {
151151
m.def("int_passthrough_noconvert", [](int arg) { return arg; }, py::arg{}.noconvert());
152152

153153
// test_tuple
154-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
155-
m.def("pair_passthrough", [](std::pair<bool, std::string> input) {
156-
return std::make_pair(input.second, input.first);
157-
}, "Return a pair in reversed order");
154+
m.def(
155+
"pair_passthrough",
156+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
157+
[](std::pair<bool, std::string> input) {
158+
return std::make_pair(input.second, input.first);
159+
},
160+
"Return a pair in reversed order");
158161
m.def("tuple_passthrough", [](std::tuple<bool, std::string, int> input) {
159162
return std::make_tuple(std::get<2>(input), std::get<1>(input), std::get<0>(input));
160163
}, "Return a triple in reversed order");

tests/test_callbacks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ TEST_SUBMODULE(callbacks, m) {
122122
// [workaround(intel)] = default does not work here
123123
// Defaulting this destructor results in linking errors with the Intel compiler
124124
// (in Debug builds only, tested with icpc (ICC) 2021.1 Beta 20200827)
125-
virtual ~AbstractBase() {}; // NOLINT(modernize-use-equals-default)
125+
virtual ~AbstractBase() {} // NOLINT(modernize-use-equals-default)
126126
virtual unsigned int func() = 0;
127127
};
128128
m.def("func_accepting_func_accepting_base",

tests/test_eigen.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ TEST_SUBMODULE(eigen, m) {
9898

9999
// test_eigen_ref_to_python
100100
// Different ways of passing via Eigen::Ref; the first and second are the Eigen-recommended
101-
// NOLINTNEXTLINE (performance-unnecessary-value-param)
102-
m.def("cholesky1", [](Eigen::Ref<MatrixXdR> x) -> Eigen::MatrixXd { return x.llt().matrixL(); });
101+
m.def("cholesky1",
102+
// NOLINTNEXTLINE (performance-unnecessary-value-param)
103+
[](Eigen::Ref<MatrixXdR> x) -> Eigen::MatrixXd { return x.llt().matrixL(); });
103104
m.def("cholesky2", [](const Eigen::Ref<const MatrixXdR> &x) -> Eigen::MatrixXd { return x.llt().matrixL(); });
104105
m.def("cholesky3", [](const Eigen::Ref<MatrixXdR> &x) -> Eigen::MatrixXd { return x.llt().matrixL(); });
105-
// NOLINTNEXTLINE (performance-unnecessary-value-param)
106-
m.def("cholesky4", [](Eigen::Ref<const MatrixXdR> x) -> Eigen::MatrixXd { return x.llt().matrixL(); });
106+
m.def("cholesky4",
107+
// NOLINTNEXTLINE (performance-unnecessary-value-param)
108+
[](Eigen::Ref<const MatrixXdR> x) -> Eigen::MatrixXd { return x.llt().matrixL(); });
107109

108110
// test_eigen_ref_mutators
109111
// Mutators: these add some value to the given element using Eigen, but Eigen should be mapping into
@@ -260,7 +262,10 @@ TEST_SUBMODULE(eigen, m) {
260262
m.def("dense_copy_r", [](const DenseMatrixR &m) -> DenseMatrixR { return m; });
261263
m.def("dense_copy_c", [](const DenseMatrixC &m) -> DenseMatrixC { return m; });
262264
// test_sparse, test_sparse_signature
263-
m.def("sparse_r", [mat]() -> SparseMatrixR { return Eigen::SparseView<Eigen::MatrixXf>(mat); }); //NOLINT(clang-analyzer-core.uninitialized.UndefReturn)
265+
m.def("sparse_r", [mat]() -> SparseMatrixR {
266+
// NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn)
267+
return Eigen::SparseView<Eigen::MatrixXf>(mat);
268+
});
264269
m.def("sparse_c", [mat]() -> SparseMatrixC { return Eigen::SparseView<Eigen::MatrixXf>(mat); });
265270
m.def("sparse_copy_r", [](const SparseMatrixR &m) -> SparseMatrixR { return m; });
266271
m.def("sparse_copy_c", [](const SparseMatrixC &m) -> SparseMatrixC { return m; });
@@ -284,9 +289,11 @@ TEST_SUBMODULE(eigen, m) {
284289
// that would allow copying (if types or strides don't match) for comparison:
285290
m.def("get_elem", &get_elem);
286291
// Now this alternative that calls the tells pybind to fail rather than copy:
287-
// NOLINTNEXTLINE (performance-unnecessary-value-param)
288-
m.def("get_elem_nocopy", [](Eigen::Ref<const Eigen::MatrixXd> m) -> double { return get_elem(m); },
289-
py::arg{}.noconvert());
292+
m.def(
293+
"get_elem_nocopy",
294+
// NOLINTNEXTLINE (performance-unnecessary-value-param)
295+
[](Eigen::Ref<const Eigen::MatrixXd> m) -> double { return get_elem(m); },
296+
py::arg{}.noconvert());
290297
// Also test a row-major-only no-copy const ref:
291298
m.def("get_elem_rm_nocopy", [](Eigen::Ref<const Eigen::Matrix<long, -1, -1, Eigen::RowMajor>> &m) -> long { return m(2, 1); },
292299
py::arg{}.noconvert());
@@ -301,20 +308,26 @@ TEST_SUBMODULE(eigen, m) {
301308
// test_issue1105
302309
// Issue #1105: when converting from a numpy two-dimensional (Nx1) or (1xN) value into a dense
303310
// eigen Vector or RowVector, the argument would fail to load because the numpy copy would
304-
// fail: numpy won't broadcast a Nx1 into a 1-dimensional vector. NOLINTNEXTLINE
311+
// fail: numpy won't broadcast a Nx1 into a 1-dimensional vector.
305312
// NOLINTNEXTLINE (performance-unnecessary-value-param)
306313
m.def("iss1105_col", [](Eigen::VectorXd) { return true; });
307314
// NOLINTNEXTLINE (performance-unnecessary-value-param)
308315
m.def("iss1105_row", [](Eigen::RowVectorXd) { return true; });
309316

310317
// test_named_arguments
311318
// Make sure named arguments are working properly:
312-
// NOLINTNEXTLINE (performance-unnecessary-value-param)
313-
m.def("matrix_multiply", [](const py::EigenDRef<const Eigen::MatrixXd> A, const py::EigenDRef<const Eigen::MatrixXd> B)
314-
-> Eigen::MatrixXd {
315-
if (A.cols() != B.rows()) throw std::domain_error("Nonconformable matrices!");
316-
return A * B;
317-
}, py::arg("A"), py::arg("B"));
319+
m.def(
320+
"matrix_multiply",
321+
// NOLINTNEXTLINE (performance-unnecessary-value-param)
322+
[](const py::EigenDRef<const Eigen::MatrixXd> A,
323+
// NOLINTNEXTLINE (performance-unnecessary-value-param)
324+
const py::EigenDRef<const Eigen::MatrixXd> B) -> Eigen::MatrixXd {
325+
if (A.cols() != B.rows())
326+
throw std::domain_error("Nonconformable matrices!");
327+
return A * B;
328+
},
329+
py::arg("A"),
330+
py::arg("B"));
318331

319332
// test_custom_operator_new
320333
py::class_<CustomOperatorNew>(m, "CustomOperatorNew")

tests/test_kwargs_and_defaults.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ TEST_SUBMODULE(kwargs_and_defaults, m) {
106106
py::arg() = 3, "j"_a = 4, py::kw_only(), "k"_a = 5, "z"_a);
107107
m.def("kw_only_mixed", [](int i, int j) { return py::make_tuple(i, j); },
108108
"i"_a, py::kw_only(), "j"_a);
109-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
110-
m.def("kw_only_plus_more", [](int i, int j, int k, py::kwargs kwargs) {
111-
return py::make_tuple(i, j, k, kwargs); },
112-
py::arg() /* positional */, py::arg("j") = -1 /* both */, py::kw_only(), py::arg("k") /* kw-only */);
109+
m.def(
110+
"kw_only_plus_more",
111+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
112+
[](int i, int j, int k, py::kwargs kwargs) { return py::make_tuple(i, j, k, kwargs); },
113+
py::arg() /* positional */,
114+
py::arg("j") = -1 /* both */,
115+
py::kw_only(),
116+
py::arg("k") /* kw-only */);
113117

114118
m.def("register_invalid_kw_only", [](py::module_ m) {
115119
m.def("bad_kw_only", [](int i, int j) { return py::make_tuple(i, j); },

tests/test_local_bindings.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ TEST_SUBMODULE(local_bindings, m) {
8686
m.def("return_self", [](LocalVec *v) { return v; });
8787
m.def("return_copy", [](const LocalVec &v) { return LocalVec(v); });
8888

89-
// Reformatting this class broke pygrep checks
90-
// NOLINTNEXTLINE
91-
class Cat : public pets::Pet { public: Cat(std::string name) : Pet(name) {}; };
89+
class Cat : public pets::Pet {
90+
public:
91+
// Reformatting this class broke pygrep checks
92+
// NOLINTNEXTLINE
93+
Cat(std::string name) : Pet(name) {}
94+
};
9295
py::class_<pets::Pet>(m, "Pet", py::module_local())
9396
.def("get_name", &pets::Pet::name);
9497
// Binding for local extending class:

tests/test_methods_and_attributes.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class NoneCastTester {
123123
public:
124124
int answer = -1;
125125
NoneCastTester() = default;
126-
NoneCastTester(int v) : answer(v) {};
126+
NoneCastTester(int v) : answer(v) {}
127127
};
128128

129129
struct StrIssue {
@@ -393,14 +393,14 @@ TEST_SUBMODULE(methods_and_attributes, m) {
393393
.def("increase_value", &RegisteredDerived::increase_value)
394394
.def_readwrite("rw_value", &RegisteredDerived::rw_value)
395395
.def_readonly("ro_value", &RegisteredDerived::ro_value)
396-
// These should trigger a static_assert if uncommented
397-
//.def_readwrite("fails", &UserType::value) // should trigger a static_assert if uncommented
398-
//.def_readonly("fails", &UserType::value) // should trigger a static_assert if uncommented
396+
// Uncommenting the next line should trigger a static_assert:
397+
// .def_readwrite("fails", &UserType::value)
398+
// Uncommenting the next line should trigger a static_assert:
399+
// .def_readonly("fails", &UserType::value)
399400
.def_property("rw_value_prop", &RegisteredDerived::get_int, &RegisteredDerived::set_int)
400401
.def_property_readonly("ro_value_prop", &RegisteredDerived::get_double)
401402
// This one is in the registered class:
402-
.def("sum", &RegisteredDerived::sum)
403-
;
403+
.def("sum", &RegisteredDerived::sum);
404404

405405
using Adapted = decltype(py::method_adaptor<RegisteredDerived>(&RegisteredDerived::do_nothing));
406406
static_assert(std::is_same<Adapted, void (RegisteredDerived::*)() const>::value, "");

tests/test_numpy_array.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,16 @@ TEST_SUBMODULE(numpy_array, sm) {
275275
// [workaround(intel)] ICC 20/21 breaks with py::arg().stuff, using py::arg{}.stuff works.
276276

277277
// Only accept the exact types:
278-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
279-
sm.def("overloaded3", [](py::array_t<int>) { return "int"; }, py::arg{}.noconvert());
280-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
281-
sm.def("overloaded3", [](py::array_t<double>) { return "double"; }, py::arg{}.noconvert());
278+
sm.def(
279+
"overloaded3",
280+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
281+
[](py::array_t<int>) { return "int"; },
282+
py::arg{}.noconvert());
283+
sm.def(
284+
"overloaded3",
285+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
286+
[](py::array_t<double>) { return "double"; },
287+
py::arg{}.noconvert());
282288

283289
// Make sure we don't do unsafe coercion (e.g. float to int) when not using forcecast, but
284290
// rather that float gets converted via the safe (conversion to double) overload:

tests/test_numpy_vectorize.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ TEST_SUBMODULE(numpy_vectorize, m) {
3838
));
3939

4040
// test_type_selection
41-
// NumPy function which only accepts specific data types
42-
// A lot of these no lints could be replaced with const refs, and probably should at some point.
43-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
44-
m.def("selective_func", [](py::array_t<int, py::array::c_style>) { return "Int branch taken."; });
45-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
46-
m.def("selective_func", [](py::array_t<float, py::array::c_style>) { return "Float branch taken."; });
47-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
48-
m.def("selective_func", [](py::array_t<std::complex<float>, py::array::c_style>) { return "Complex float branch taken."; });
49-
41+
// A lot of these no lints could be replaced with const refs,
42+
// and probably should at some point.
43+
m.def("selective_func",
44+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
45+
[](py::array_t<int, py::array::c_style>) { return "Int branch taken."; });
46+
m.def("selective_func",
47+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
48+
[](py::array_t<float, py::array::c_style>) { return "Float branch taken."; });
49+
m.def("selective_func",
50+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
51+
[](py::array_t<std::complex<float>, py::array::c_style>) {
52+
return "Complex float branch taken.";
53+
});
5054

5155
// test_passthrough_arguments
5256
// Passthrough test: references and non-pod types should be automatically passed through (in the

tests/test_pickling.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// clang-format off
21
/*
32
tests/test_pickling.cpp -- pickle support
43
@@ -11,8 +10,6 @@
1110

1211
#include "pybind11_tests.h"
1312

14-
// clang-format on
15-
1613
#include <memory>
1714
#include <stdexcept>
1815
#include <utility>
@@ -61,8 +58,6 @@ void wrap(py::module m) {
6158

6259
} // namespace exercise_trampoline
6360

64-
// clang-format off
65-
6661
TEST_SUBMODULE(pickling, m) {
6762
// test_roundtrip
6863
class Pickleable {

tests/test_pytypes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,9 @@ TEST_SUBMODULE(pytypes, m) {
258258
// NOLINTNEXTLINE(performance-unnecessary-value-param)
259259
m.def("convert_to_pybind11_str", [](py::object o) { return py::str(o); });
260260

261-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
262-
m.def("nonconverting_constructor", [](std::string type, py::object value, bool move) -> py::object {
261+
m.def("nonconverting_constructor",
262+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
263+
[](std::string type, py::object value, bool move) -> py::object {
263264
if (type == "bytes") {
264265
return move ? py::bytes(std::move(value)) : py::bytes(value);
265266
}

tests/test_smart_ptr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ template <typename T> class huge_unique_ptr {
2424
std::unique_ptr<T> ptr;
2525
uint64_t padding[10];
2626
public:
27-
huge_unique_ptr(T *p) : ptr(p) {};
27+
huge_unique_ptr(T *p) : ptr(p) {}
2828
T *get() { return ptr.get(); }
2929
};
3030

tests/test_stl.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,15 @@ TEST_SUBMODULE(stl, m) {
299299
m.def("stl_pass_by_pointer", [](std::vector<int>* v) { return *v; }, "v"_a=nullptr);
300300

301301
// #1258: pybind11/stl.h converts string to vector<string>
302-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
303-
m.def("func_with_string_or_vector_string_arg_overload", [](std::vector<std::string>) { return 1; });
304-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
305-
m.def("func_with_string_or_vector_string_arg_overload", [](std::list<std::string>) { return 2; });
306-
// NOLINTNEXTLINE(performance-unnecessary-value-param)
307-
m.def("func_with_string_or_vector_string_arg_overload", [](std::string) { return 3; });
302+
m.def("func_with_string_or_vector_string_arg_overload",
303+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
304+
[](std::vector<std::string>) { return 1; });
305+
m.def("func_with_string_or_vector_string_arg_overload",
306+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
307+
[](std::list<std::string>) { return 2; });
308+
m.def("func_with_string_or_vector_string_arg_overload",
309+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
310+
[](std::string) { return 3; });
308311

309312
class Placeholder {
310313
public:

0 commit comments

Comments
 (0)