mirror of
https://github.com/pybind/pybind11.git
synced 2026-06-08 23:39:12 +00:00
clang-tidy readability-qualified-auto (#3702)
* Adding readability-qualified-auto to .clang-tidy
Ported from @henryiii's 287527f705
* fix: support Python < 3.6
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
committed by
GitHub
parent
b4f5350d0d
commit
7769e7719c
@@ -89,7 +89,7 @@ TEST_SUBMODULE(buffers, m) {
|
||||
throw std::runtime_error("Incompatible buffer format!");
|
||||
}
|
||||
|
||||
auto v = new Matrix(info.shape[0], info.shape[1]);
|
||||
auto *v = new Matrix(info.shape[0], info.shape[1]);
|
||||
memcpy(v->data(), info.ptr, sizeof(float) * (size_t) (v->rows() * v->cols()));
|
||||
return v;
|
||||
}))
|
||||
|
||||
@@ -277,7 +277,7 @@ TEST_SUBMODULE(builtin_casters, m) {
|
||||
m.def("refwrap_list", [](bool copy) {
|
||||
static IncType x1(1), x2(2);
|
||||
py::list l;
|
||||
for (auto &f : {std::ref(x1), std::ref(x2)}) {
|
||||
for (const auto &f : {std::ref(x1), std::ref(x2)}) {
|
||||
l.append(py::cast(f, copy ? py::return_value_policy::copy
|
||||
: py::return_value_policy::reference));
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ TEST_SUBMODULE(call_policies, m) {
|
||||
// but it's unclear how to test it without `PyGILState_GetThisThreadState`.
|
||||
auto report_gil_status = []() {
|
||||
auto is_gil_held = false;
|
||||
if (auto tstate = py::detail::get_thread_state_unchecked()) {
|
||||
if (auto *tstate = py::detail::get_thread_state_unchecked()) {
|
||||
is_gil_held = (tstate == PyGILState_GetThisThreadState());
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ TEST_SUBMODULE(callbacks, m) {
|
||||
py::arg("expect_none") = false);
|
||||
m.def("test_dummy_function", [](const std::function<int(int)> &f) -> std::string {
|
||||
using fn_type = int (*)(int);
|
||||
auto result = f.target<fn_type>();
|
||||
const auto *result = f.target<fn_type>();
|
||||
if (!result) {
|
||||
auto r = f(1);
|
||||
return "can't convert to function pointer: eval(1) = " + std::to_string(r);
|
||||
|
||||
@@ -255,7 +255,7 @@ TEST_SUBMODULE(class_, m) {
|
||||
return py::str().release().ptr();
|
||||
};
|
||||
|
||||
auto def = new PyMethodDef{"f", f, METH_VARARGS, nullptr};
|
||||
auto *def = new PyMethodDef{"f", f, METH_VARARGS, nullptr};
|
||||
py::capsule def_capsule(def, [](void *ptr) { delete reinterpret_cast<PyMethodDef *>(ptr); });
|
||||
return py::reinterpret_steal<py::object>(PyCFunction_NewEx(def, def_capsule.ptr(), m.ptr()));
|
||||
}());
|
||||
|
||||
@@ -240,8 +240,8 @@ TEST_CASE("Subinterpreter") {
|
||||
REQUIRE(has_pybind11_internals_static());
|
||||
|
||||
/// Create and switch to a subinterpreter.
|
||||
auto main_tstate = PyThreadState_Get();
|
||||
auto sub_tstate = Py_NewInterpreter();
|
||||
auto *main_tstate = PyThreadState_Get();
|
||||
auto *sub_tstate = Py_NewInterpreter();
|
||||
|
||||
// Subinterpreters get their own copy of builtins. detail::get_internals() still
|
||||
// works by returning from the static variable, i.e. all interpreters share a single
|
||||
|
||||
@@ -89,7 +89,7 @@ template<typename... Ix> arr data_t(const arr_t& a, Ix... index) {
|
||||
}
|
||||
|
||||
template<typename... Ix> arr& mutate_data(arr& a, Ix... index) {
|
||||
auto ptr = (uint8_t *) a.mutable_data(index...);
|
||||
auto *ptr = (uint8_t *) a.mutable_data(index...);
|
||||
for (py::ssize_t i = 0; i < a.nbytes() - a.offset_at(index...); i++) {
|
||||
ptr[i] = (uint8_t) (ptr[i] * 2);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ template <typename S>
|
||||
py::array_t<S, 0> create_recarray(size_t n) {
|
||||
auto arr = mkarray_via_buffer<S>(n);
|
||||
auto req = arr.request();
|
||||
auto ptr = static_cast<S*>(req.ptr);
|
||||
auto *ptr = static_cast<S *>(req.ptr);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
SET_TEST_VALS(ptr[i], i);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ py::array_t<S, 0> create_recarray(size_t n) {
|
||||
template <typename S>
|
||||
py::list print_recarray(py::array_t<S, 0> arr) {
|
||||
const auto req = arr.request();
|
||||
const auto ptr = static_cast<S*>(req.ptr);
|
||||
auto *const ptr = static_cast<S *>(req.ptr);
|
||||
auto l = py::list();
|
||||
for (py::ssize_t i = 0; i < req.size; i++) {
|
||||
std::stringstream ss;
|
||||
@@ -192,8 +192,8 @@ py::array_t<int32_t, 0> test_array_ctors(int i) {
|
||||
std::vector<py::ssize_t> shape { 3, 2 };
|
||||
std::vector<py::ssize_t> strides { 8, 4 };
|
||||
|
||||
auto ptr = data.data();
|
||||
auto vptr = (void *) ptr;
|
||||
auto *ptr = data.data();
|
||||
auto *vptr = (void *) ptr;
|
||||
auto dtype = py::dtype("int32");
|
||||
|
||||
py::buffer_info buf_ndim1(vptr, 4, "i", 6);
|
||||
@@ -328,7 +328,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
|
||||
m.def("create_rec_nested", [](size_t n) { // test_signature
|
||||
py::array_t<NestedStruct, 0> arr = mkarray_via_buffer<NestedStruct>(n);
|
||||
auto req = arr.request();
|
||||
auto ptr = static_cast<NestedStruct*>(req.ptr);
|
||||
auto *ptr = static_cast<NestedStruct *>(req.ptr);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
SET_TEST_VALS(ptr[i].a, i);
|
||||
SET_TEST_VALS(ptr[i].b, i + 1);
|
||||
@@ -339,7 +339,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
|
||||
m.def("create_rec_partial_nested", [](size_t n) {
|
||||
py::array_t<PartialNestedStruct, 0> arr = mkarray_via_buffer<PartialNestedStruct>(n);
|
||||
auto req = arr.request();
|
||||
auto ptr = static_cast<PartialNestedStruct*>(req.ptr);
|
||||
auto *ptr = static_cast<PartialNestedStruct *>(req.ptr);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
SET_TEST_VALS(ptr[i].a, i);
|
||||
}
|
||||
@@ -397,14 +397,14 @@ TEST_SUBMODULE(numpy_dtypes, m) {
|
||||
m.def("test_dtype_ctors", &test_dtype_ctors);
|
||||
m.def("test_dtype_kind", [dtype_names]() {
|
||||
py::list list;
|
||||
for (auto &dt_name : dtype_names) {
|
||||
for (const auto &dt_name : dtype_names) {
|
||||
list.append(py::dtype(dt_name).kind());
|
||||
}
|
||||
return list;
|
||||
});
|
||||
m.def("test_dtype_char_", [dtype_names]() {
|
||||
py::list list;
|
||||
for (auto &dt_name : dtype_names) {
|
||||
for (const auto &dt_name : dtype_names) {
|
||||
list.append(py::dtype(dt_name).char_());
|
||||
}
|
||||
return list;
|
||||
@@ -430,7 +430,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
|
||||
py::array_t<StringStruct, 0> arr = mkarray_via_buffer<StringStruct>(non_empty ? 4 : 0);
|
||||
if (non_empty) {
|
||||
auto req = arr.request();
|
||||
auto ptr = static_cast<StringStruct*>(req.ptr);
|
||||
auto *ptr = static_cast<StringStruct *>(req.ptr);
|
||||
for (py::ssize_t i = 0; i < req.size * req.itemsize; i++) {
|
||||
static_cast<char *>(req.ptr)[i] = 0;
|
||||
}
|
||||
@@ -450,7 +450,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
|
||||
// test_array_array
|
||||
m.def("create_array_array", [](size_t n) {
|
||||
py::array_t<ArrayStruct, 0> arr = mkarray_via_buffer<ArrayStruct>(n);
|
||||
auto ptr = (ArrayStruct *) arr.mutable_data();
|
||||
auto *ptr = (ArrayStruct *) arr.mutable_data();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
for (size_t j = 0; j < 3; j++) {
|
||||
for (size_t k = 0; k < 4; k++) {
|
||||
@@ -476,7 +476,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
|
||||
// test_enum_array
|
||||
m.def("create_enum_array", [](size_t n) {
|
||||
py::array_t<EnumStruct, 0> arr = mkarray_via_buffer<EnumStruct>(n);
|
||||
auto ptr = (EnumStruct *) arr.mutable_data();
|
||||
auto *ptr = (EnumStruct *) arr.mutable_data();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
ptr[i].e1 = static_cast<E1>(-1 + ((int) i % 2) * 2);
|
||||
ptr[i].e2 = static_cast<E2>(1 + (i % 2));
|
||||
@@ -488,7 +488,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
|
||||
// test_complex_array
|
||||
m.def("create_complex_array", [](size_t n) {
|
||||
py::array_t<ComplexStruct, 0> arr = mkarray_via_buffer<ComplexStruct>(n);
|
||||
auto ptr = (ComplexStruct *) arr.mutable_data();
|
||||
auto *ptr = (ComplexStruct *) arr.mutable_data();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
ptr[i].cflt.real(float(i));
|
||||
ptr[i].cflt.imag(float(i) + 0.25f);
|
||||
|
||||
@@ -146,7 +146,7 @@ TEST_SUBMODULE(pytypes, m) {
|
||||
m.def("return_capsule_with_name_and_destructor", []() {
|
||||
auto capsule = py::capsule((void *) 12345, "pointer type description", [](PyObject *ptr) {
|
||||
if (ptr) {
|
||||
auto name = PyCapsule_GetName(ptr);
|
||||
const auto *name = PyCapsule_GetName(ptr);
|
||||
py::print("destructing capsule ({}, '{}')"_s.format(
|
||||
(size_t) PyCapsule_GetPointer(ptr, name), name
|
||||
));
|
||||
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
static void cleanupAllInstances() {
|
||||
auto tmp = std::move(myobject4_instances);
|
||||
myobject4_instances.clear();
|
||||
for (auto o : tmp) {
|
||||
for (auto *o : tmp) {
|
||||
delete o;
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,7 @@ public:
|
||||
static void cleanupAllInstances() {
|
||||
auto tmp = std::move(myobject4a_instances);
|
||||
myobject4a_instances.clear();
|
||||
for (auto o : tmp) {
|
||||
for (auto *o : tmp) {
|
||||
delete o;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
};
|
||||
|
||||
template <class Container> Container *one_to_n(int n) {
|
||||
auto v = new Container();
|
||||
auto *v = new Container();
|
||||
for (int i = 1; i <= n; i++) {
|
||||
v->emplace_back(i);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ template <class Container> Container *one_to_n(int n) {
|
||||
}
|
||||
|
||||
template <class Map> Map *times_ten(int n) {
|
||||
auto m = new Map();
|
||||
auto *m = new Map();
|
||||
for (int i = 1; i <= n; i++) {
|
||||
m->emplace(int(i), E_nc(10 * i));
|
||||
}
|
||||
@@ -57,7 +57,7 @@ template <class Map> Map *times_ten(int n) {
|
||||
}
|
||||
|
||||
template <class NestMap> NestMap *times_hundred(int n) {
|
||||
auto m = new NestMap();
|
||||
auto *m = new NestMap();
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
(*m)[i].emplace(int(j * 10), E_nc(100 * j));
|
||||
@@ -99,16 +99,15 @@ TEST_SUBMODULE(stl_binders, m) {
|
||||
m.def("get_umnc", ×_ten<std::unordered_map<int, E_nc>>);
|
||||
// Issue #1885: binding nested std::map<X, Container<E>> with E non-copyable
|
||||
py::bind_map<std::map<int, std::vector<E_nc>>>(m, "MapVecENC");
|
||||
m.def("get_nvnc", [](int n)
|
||||
{
|
||||
auto m = new std::map<int, std::vector<E_nc>>();
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
(*m)[i].emplace_back(j);
|
||||
}
|
||||
m.def("get_nvnc", [](int n) {
|
||||
auto *m = new std::map<int, std::vector<E_nc>>();
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= n; j++) {
|
||||
(*m)[i].emplace_back(j);
|
||||
}
|
||||
return m;
|
||||
});
|
||||
}
|
||||
return m;
|
||||
});
|
||||
py::bind_map<std::map<int, std::map<int, E_nc>>>(m, "MapMapENC");
|
||||
m.def("get_nmnc", ×_hundred<std::map<int, std::map<int, E_nc>>>);
|
||||
py::bind_map<std::unordered_map<int, std::unordered_map<int, E_nc>>>(m, "UmapUmapENC");
|
||||
|
||||
Reference in New Issue
Block a user