Unverified Commit 7769e771 authored by Ralf W. Grosse-Kunstleve's avatar Ralf W. Grosse-Kunstleve Committed by GitHub
Browse files

clang-tidy readability-qualified-auto (#3702)

* Adding readability-qualified-auto to .clang-tidy

Ported from @henryiii's https://github.com/pybind/pybind11/pull/3683/commits/287527f705c8badee8ba9f6278d691fe0450ae43



* fix: support Python < 3.6
Co-authored-by: default avatarHenry Schreiner <henryschreineriii@gmail.com>
parent b4f5350d
...@@ -89,7 +89,7 @@ template<typename... Ix> arr data_t(const arr_t& a, Ix... index) { ...@@ -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) { 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++) { for (py::ssize_t i = 0; i < a.nbytes() - a.offset_at(index...); i++) {
ptr[i] = (uint8_t) (ptr[i] * 2); ptr[i] = (uint8_t) (ptr[i] * 2);
} }
......
...@@ -165,7 +165,7 @@ template <typename S> ...@@ -165,7 +165,7 @@ template <typename S>
py::array_t<S, 0> create_recarray(size_t n) { py::array_t<S, 0> create_recarray(size_t n) {
auto arr = mkarray_via_buffer<S>(n); auto arr = mkarray_via_buffer<S>(n);
auto req = arr.request(); 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++) { for (size_t i = 0; i < n; i++) {
SET_TEST_VALS(ptr[i], i); SET_TEST_VALS(ptr[i], i);
} }
...@@ -175,7 +175,7 @@ py::array_t<S, 0> create_recarray(size_t n) { ...@@ -175,7 +175,7 @@ py::array_t<S, 0> create_recarray(size_t n) {
template <typename S> template <typename S>
py::list print_recarray(py::array_t<S, 0> arr) { py::list print_recarray(py::array_t<S, 0> arr) {
const auto req = arr.request(); 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(); auto l = py::list();
for (py::ssize_t i = 0; i < req.size; i++) { for (py::ssize_t i = 0; i < req.size; i++) {
std::stringstream ss; std::stringstream ss;
...@@ -192,8 +192,8 @@ py::array_t<int32_t, 0> test_array_ctors(int i) { ...@@ -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> shape { 3, 2 };
std::vector<py::ssize_t> strides { 8, 4 }; std::vector<py::ssize_t> strides { 8, 4 };
auto ptr = data.data(); auto *ptr = data.data();
auto vptr = (void *) ptr; auto *vptr = (void *) ptr;
auto dtype = py::dtype("int32"); auto dtype = py::dtype("int32");
py::buffer_info buf_ndim1(vptr, 4, "i", 6); py::buffer_info buf_ndim1(vptr, 4, "i", 6);
...@@ -328,7 +328,7 @@ TEST_SUBMODULE(numpy_dtypes, m) { ...@@ -328,7 +328,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
m.def("create_rec_nested", [](size_t n) { // test_signature m.def("create_rec_nested", [](size_t n) { // test_signature
py::array_t<NestedStruct, 0> arr = mkarray_via_buffer<NestedStruct>(n); py::array_t<NestedStruct, 0> arr = mkarray_via_buffer<NestedStruct>(n);
auto req = arr.request(); 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++) { for (size_t i = 0; i < n; i++) {
SET_TEST_VALS(ptr[i].a, i); SET_TEST_VALS(ptr[i].a, i);
SET_TEST_VALS(ptr[i].b, i + 1); SET_TEST_VALS(ptr[i].b, i + 1);
...@@ -339,7 +339,7 @@ TEST_SUBMODULE(numpy_dtypes, m) { ...@@ -339,7 +339,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
m.def("create_rec_partial_nested", [](size_t n) { m.def("create_rec_partial_nested", [](size_t n) {
py::array_t<PartialNestedStruct, 0> arr = mkarray_via_buffer<PartialNestedStruct>(n); py::array_t<PartialNestedStruct, 0> arr = mkarray_via_buffer<PartialNestedStruct>(n);
auto req = arr.request(); 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++) { for (size_t i = 0; i < n; i++) {
SET_TEST_VALS(ptr[i].a, i); SET_TEST_VALS(ptr[i].a, i);
} }
...@@ -397,14 +397,14 @@ TEST_SUBMODULE(numpy_dtypes, m) { ...@@ -397,14 +397,14 @@ TEST_SUBMODULE(numpy_dtypes, m) {
m.def("test_dtype_ctors", &test_dtype_ctors); m.def("test_dtype_ctors", &test_dtype_ctors);
m.def("test_dtype_kind", [dtype_names]() { m.def("test_dtype_kind", [dtype_names]() {
py::list list; py::list list;
for (auto &dt_name : dtype_names) { for (const auto &dt_name : dtype_names) {
list.append(py::dtype(dt_name).kind()); list.append(py::dtype(dt_name).kind());
} }
return list; return list;
}); });
m.def("test_dtype_char_", [dtype_names]() { m.def("test_dtype_char_", [dtype_names]() {
py::list list; py::list list;
for (auto &dt_name : dtype_names) { for (const auto &dt_name : dtype_names) {
list.append(py::dtype(dt_name).char_()); list.append(py::dtype(dt_name).char_());
} }
return list; return list;
...@@ -430,7 +430,7 @@ TEST_SUBMODULE(numpy_dtypes, m) { ...@@ -430,7 +430,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
py::array_t<StringStruct, 0> arr = mkarray_via_buffer<StringStruct>(non_empty ? 4 : 0); py::array_t<StringStruct, 0> arr = mkarray_via_buffer<StringStruct>(non_empty ? 4 : 0);
if (non_empty) { if (non_empty) {
auto req = arr.request(); 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++) { for (py::ssize_t i = 0; i < req.size * req.itemsize; i++) {
static_cast<char *>(req.ptr)[i] = 0; static_cast<char *>(req.ptr)[i] = 0;
} }
...@@ -450,7 +450,7 @@ TEST_SUBMODULE(numpy_dtypes, m) { ...@@ -450,7 +450,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
// test_array_array // test_array_array
m.def("create_array_array", [](size_t n) { m.def("create_array_array", [](size_t n) {
py::array_t<ArrayStruct, 0> arr = mkarray_via_buffer<ArrayStruct>(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 i = 0; i < n; i++) {
for (size_t j = 0; j < 3; j++) { for (size_t j = 0; j < 3; j++) {
for (size_t k = 0; k < 4; k++) { for (size_t k = 0; k < 4; k++) {
...@@ -476,7 +476,7 @@ TEST_SUBMODULE(numpy_dtypes, m) { ...@@ -476,7 +476,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
// test_enum_array // test_enum_array
m.def("create_enum_array", [](size_t n) { m.def("create_enum_array", [](size_t n) {
py::array_t<EnumStruct, 0> arr = mkarray_via_buffer<EnumStruct>(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++) { for (size_t i = 0; i < n; i++) {
ptr[i].e1 = static_cast<E1>(-1 + ((int) i % 2) * 2); ptr[i].e1 = static_cast<E1>(-1 + ((int) i % 2) * 2);
ptr[i].e2 = static_cast<E2>(1 + (i % 2)); ptr[i].e2 = static_cast<E2>(1 + (i % 2));
...@@ -488,7 +488,7 @@ TEST_SUBMODULE(numpy_dtypes, m) { ...@@ -488,7 +488,7 @@ TEST_SUBMODULE(numpy_dtypes, m) {
// test_complex_array // test_complex_array
m.def("create_complex_array", [](size_t n) { m.def("create_complex_array", [](size_t n) {
py::array_t<ComplexStruct, 0> arr = mkarray_via_buffer<ComplexStruct>(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++) { for (size_t i = 0; i < n; i++) {
ptr[i].cflt.real(float(i)); ptr[i].cflt.real(float(i));
ptr[i].cflt.imag(float(i) + 0.25f); ptr[i].cflt.imag(float(i) + 0.25f);
......
...@@ -146,7 +146,7 @@ TEST_SUBMODULE(pytypes, m) { ...@@ -146,7 +146,7 @@ TEST_SUBMODULE(pytypes, m) {
m.def("return_capsule_with_name_and_destructor", []() { m.def("return_capsule_with_name_and_destructor", []() {
auto capsule = py::capsule((void *) 12345, "pointer type description", [](PyObject *ptr) { auto capsule = py::capsule((void *) 12345, "pointer type description", [](PyObject *ptr) {
if (ptr) { if (ptr) {
auto name = PyCapsule_GetName(ptr); const auto *name = PyCapsule_GetName(ptr);
py::print("destructing capsule ({}, '{}')"_s.format( py::print("destructing capsule ({}, '{}')"_s.format(
(size_t) PyCapsule_GetPointer(ptr, name), name (size_t) PyCapsule_GetPointer(ptr, name), name
)); ));
......
...@@ -113,7 +113,7 @@ public: ...@@ -113,7 +113,7 @@ public:
static void cleanupAllInstances() { static void cleanupAllInstances() {
auto tmp = std::move(myobject4_instances); auto tmp = std::move(myobject4_instances);
myobject4_instances.clear(); myobject4_instances.clear();
for (auto o : tmp) { for (auto *o : tmp) {
delete o; delete o;
} }
} }
...@@ -141,7 +141,7 @@ public: ...@@ -141,7 +141,7 @@ public:
static void cleanupAllInstances() { static void cleanupAllInstances() {
auto tmp = std::move(myobject4a_instances); auto tmp = std::move(myobject4a_instances);
myobject4a_instances.clear(); myobject4a_instances.clear();
for (auto o : tmp) { for (auto *o : tmp) {
delete o; delete o;
} }
} }
......
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
}; };
template <class Container> Container *one_to_n(int n) { template <class Container> Container *one_to_n(int n) {
auto v = new Container(); auto *v = new Container();
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
v->emplace_back(i); v->emplace_back(i);
} }
...@@ -49,7 +49,7 @@ template <class Container> Container *one_to_n(int n) { ...@@ -49,7 +49,7 @@ template <class Container> Container *one_to_n(int n) {
} }
template <class Map> Map *times_ten(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++) { for (int i = 1; i <= n; i++) {
m->emplace(int(i), E_nc(10 * i)); m->emplace(int(i), E_nc(10 * i));
} }
...@@ -57,7 +57,7 @@ template <class Map> Map *times_ten(int n) { ...@@ -57,7 +57,7 @@ template <class Map> Map *times_ten(int n) {
} }
template <class NestMap> NestMap *times_hundred(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 i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) { for (int j = 1; j <= n; j++) {
(*m)[i].emplace(int(j * 10), E_nc(100 * j)); (*m)[i].emplace(int(j * 10), E_nc(100 * j));
...@@ -99,16 +99,15 @@ TEST_SUBMODULE(stl_binders, m) { ...@@ -99,16 +99,15 @@ TEST_SUBMODULE(stl_binders, m) {
m.def("get_umnc", &times_ten<std::unordered_map<int, E_nc>>); m.def("get_umnc", &times_ten<std::unordered_map<int, E_nc>>);
// Issue #1885: binding nested std::map<X, Container<E>> with E non-copyable // 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"); py::bind_map<std::map<int, std::vector<E_nc>>>(m, "MapVecENC");
m.def("get_nvnc", [](int n) m.def("get_nvnc", [](int n) {
{ auto *m = new std::map<int, std::vector<E_nc>>();
auto m = new std::map<int, std::vector<E_nc>>(); for (int i = 1; i <= n; i++) {
for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) {
for (int j = 1; j <= n; j++) { (*m)[i].emplace_back(j);
(*m)[i].emplace_back(j);
}
} }
return m; }
}); return m;
});
py::bind_map<std::map<int, std::map<int, E_nc>>>(m, "MapMapENC"); py::bind_map<std::map<int, std::map<int, E_nc>>>(m, "MapMapENC");
m.def("get_nmnc", &times_hundred<std::map<int, std::map<int, E_nc>>>); m.def("get_nmnc", &times_hundred<std::map<int, std::map<int, E_nc>>>);
py::bind_map<std::unordered_map<int, std::unordered_map<int, E_nc>>>(m, "UmapUmapENC"); py::bind_map<std::unordered_map<int, std::unordered_map<int, E_nc>>>(m, "UmapUmapENC");
......
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