From b72cebeb228e839caa13fa0269bd15676e130def Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Mon, 9 Nov 2020 19:10:19 +0100 Subject: [PATCH] style: clang-tidy: modernize-use-using (#2645) * style: clang-tidy: modernize-use-using * style: more clang-tidy checking Co-authored-by: Henry Schreiner --- .github/workflows/format.yml | 7 ++++++- include/pybind11/cast.h | 2 +- include/pybind11/chrono.h | 2 +- include/pybind11/detail/common.h | 2 +- include/pybind11/eigen.h | 8 ++++---- include/pybind11/numpy.h | 2 +- include/pybind11/pybind11.h | 2 +- tests/test_copy_move.cpp | 6 +++--- tests/test_eigen.cpp | 7 ++++--- tests/test_embed/CMakeLists.txt | 2 +- 10 files changed, 23 insertions(+), 17 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 708a8eef1..5cebed17d 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -35,7 +35,12 @@ jobs: run: apt-get update && apt-get install -y python3-dev python3-pytest - name: Configure - run: cmake -S . -B build -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);--warnings-as-errors=*" + run: > + cmake -S . -B build + -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);--warnings-as-errors=*" + -DDOWNLOAD_EIGEN=ON + -DDOWNLOAD_CATCH=ON + -DCMAKE_CXX_STANDARD=17 - name: Build run: cmake --build build -j 2 diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index d6e440f78..11c61a441 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1240,7 +1240,7 @@ template struct string_caster { #endif } - object utfNbytes = reinterpret_steal(PyUnicode_AsEncodedString( + auto utfNbytes = reinterpret_steal(PyUnicode_AsEncodedString( load_src.ptr(), UTF_N == 8 ? "utf-8" : UTF_N == 16 ? "utf-16" : "utf-32", nullptr)); if (!utfNbytes) { PyErr_Clear(); return false; } diff --git a/include/pybind11/chrono.h b/include/pybind11/chrono.h index cbe9acec3..c3681102d 100644 --- a/include/pybind11/chrono.h +++ b/include/pybind11/chrono.h @@ -32,7 +32,7 @@ PYBIND11_NAMESPACE_BEGIN(detail) template class duration_caster { public: - typedef typename type::rep rep; + using rep = typename type::rep; using period = typename type::period; using days = std::chrono::duration>; diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 9ee4dd2d7..3e4893649 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -494,7 +494,7 @@ using std::make_index_sequence; #else template struct index_sequence { }; template struct make_index_sequence_impl : make_index_sequence_impl { }; -template struct make_index_sequence_impl <0, S...> { typedef index_sequence type; }; +template struct make_index_sequence_impl <0, S...> { using type = index_sequence; }; template using make_index_sequence = typename make_index_sequence_impl::type; #endif diff --git a/include/pybind11/eigen.h b/include/pybind11/eigen.h index 58582b2ce..e8c6f6339 100644 --- a/include/pybind11/eigen.h +++ b/include/pybind11/eigen.h @@ -432,7 +432,7 @@ public: if (!need_copy) { // We don't need a converting copy, but we also need to check whether the strides are // compatible with the Ref's stride requirements - Array aref = reinterpret_borrow(src); + auto aref = reinterpret_borrow(src); if (aref && (!need_writeable || aref.writeable())) { fits = props::conformable(aref); @@ -539,9 +539,9 @@ public: template struct type_caster::value>> { - typedef typename Type::Scalar Scalar; - typedef remove_reference_t().outerIndexPtr())> StorageIndex; - typedef typename Type::Index Index; + using Scalar = typename Type::Scalar; + using StorageIndex = remove_reference_t().outerIndexPtr())>; + using Index = typename Type::Index; static constexpr bool rowMajor = Type::IsRowMajor; bool load(handle src, bool) { diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 2c2ab7889..019f5688e 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -772,7 +772,7 @@ public: int(new_shape->size()) }; // try to resize, set ordering param to -1 cause it's not used anyway - object new_array = reinterpret_steal( + auto new_array = reinterpret_steal( detail::npy_api::get().PyArray_Resize_(m_ptr, &d, int(refcheck), -1) ); if (!new_array) throw error_already_set(); diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 761f2a717..4cc5445d3 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1842,7 +1842,7 @@ template ()), typename... Extra> iterator make_iterator(Iterator first, Sentinel last, Extra &&... extra) { - typedef detail::iterator_state state; + using state = detail::iterator_state; if (!detail::get_type_info(typeid(state), false)) { class_(handle(), "iterator", pybind11::module_local()) diff --git a/tests/test_copy_move.cpp b/tests/test_copy_move.cpp index 05d5c4767..2704217aa 100644 --- a/tests/test_copy_move.cpp +++ b/tests/test_copy_move.cpp @@ -116,9 +116,9 @@ TEST_SUBMODULE(copy_move_policies, m) { r += py::cast(o).value; /* moves */ r += py::cast(o).value; /* moves */ r += py::cast(o).value; /* copies */ - MoveOrCopyInt m1(py::cast(o)); /* moves */ - MoveOnlyInt m2(py::cast(o)); /* moves */ - CopyOnlyInt m3(py::cast(o)); /* copies */ + auto m1(py::cast(o)); /* moves */ + auto m2(py::cast(o)); /* moves */ + auto m3(py::cast(o)); /* copies */ r += m1.value + m2.value + m3.value; return r; diff --git a/tests/test_eigen.cpp b/tests/test_eigen.cpp index 807d0a311..2cc2243d6 100644 --- a/tests/test_eigen.cpp +++ b/tests/test_eigen.cpp @@ -61,8 +61,9 @@ double get_elem(Eigen::Ref m) { return m(2, 1); }; // reference is referencing rows/columns correctly). template Eigen::MatrixXd adjust_matrix(MatrixArgType m) { Eigen::MatrixXd ret(m); - for (int c = 0; c < m.cols(); c++) for (int r = 0; r < m.rows(); r++) - ret(r, c) += 10*r + 100*c; + for (int c = 0; c < m.cols(); c++) + for (int r = 0; r < m.rows(); r++) + ret(r, c) += 10*r + 100*c; // NOLINT(clang-analyzer-core.uninitialized.Assign) return ret; } @@ -255,7 +256,7 @@ TEST_SUBMODULE(eigen, m) { m.def("dense_copy_r", [](const DenseMatrixR &m) -> DenseMatrixR { return m; }); m.def("dense_copy_c", [](const DenseMatrixC &m) -> DenseMatrixC { return m; }); // test_sparse, test_sparse_signature - m.def("sparse_r", [mat]() -> SparseMatrixR { return Eigen::SparseView(mat); }); + m.def("sparse_r", [mat]() -> SparseMatrixR { return Eigen::SparseView(mat); }); //NOLINT(clang-analyzer-core.uninitialized.UndefReturn) m.def("sparse_c", [mat]() -> SparseMatrixC { return Eigen::SparseView(mat); }); m.def("sparse_copy_r", [](const SparseMatrixR &m) -> SparseMatrixR { return m; }); m.def("sparse_copy_c", [](const SparseMatrixC &m) -> SparseMatrixC { return m; }); diff --git a/tests/test_embed/CMakeLists.txt b/tests/test_embed/CMakeLists.txt index 2e298fa7e..fabcb24ea 100644 --- a/tests/test_embed/CMakeLists.txt +++ b/tests/test_embed/CMakeLists.txt @@ -4,7 +4,7 @@ if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STR return() endif() -find_package(Catch 2.13.0) +find_package(Catch 2.13.2) if(CATCH_FOUND) message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}")