From 93a376a40afc7c91ae0d10f7cf1821643165affc Mon Sep 17 00:00:00 2001 From: Xiaofei Wang <6218006+wangxf123456@users.noreply.github.com> Date: Tue, 25 Jan 2022 16:43:11 -0800 Subject: [PATCH] [smart_holder] Add missing test case to CMakeLists.txt (#3645) * Add missing test case to CMakeLists.txt * Fix warnings * Fix Clangtidy --- tests/CMakeLists.txt | 1 + tests/test_class_sh_void_ptr_capsule.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index daae2b3f5..1c59c193b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -136,6 +136,7 @@ set(PYBIND11_TEST_FILES test_class_sh_trampoline_unique_ptr test_class_sh_unique_ptr_member test_class_sh_virtual_py_cpp_mix + test_class_sh_void_ptr_capsule test_classh_mock test_const_name test_constants_and_functions diff --git a/tests/test_class_sh_void_ptr_capsule.cpp b/tests/test_class_sh_void_ptr_capsule.cpp index 7f0b0a158..f8e312dcf 100644 --- a/tests/test_class_sh_void_ptr_capsule.cpp +++ b/tests/test_class_sh_void_ptr_capsule.cpp @@ -20,6 +20,7 @@ namespace class_sh_void_ptr_capsule { // Conveniently, the helper also serves to keep track of `capsule_generated`. struct HelperBase { HelperBase() = default; + HelperBase(const HelperBase &) = delete; virtual ~HelperBase() = default; bool capsule_generated = false; @@ -45,7 +46,7 @@ struct NoConversion: public HelperBase { }; struct NoCapsuleReturned: public HelperBase { - int get() const { return 103; } + int get() const override { return 103; } PyObject* as_pybind11_tests_class_sh_void_ptr_capsule_NoCapsuleReturned() { capsule_generated = true; @@ -72,7 +73,7 @@ int get_from_valid_capsule(const Valid* c) { return c->get(); } -int get_from_shared_ptr_valid_capsule(std::shared_ptr c) { +int get_from_shared_ptr_valid_capsule(const std::shared_ptr &c) { return c->get(); } @@ -109,7 +110,7 @@ TEST_SUBMODULE(class_sh_void_ptr_capsule, m) { .def(py::init<>()) .def("as_pybind11_tests_class_sh_void_ptr_capsule_Valid", [](HelperBase* self) { - Valid *obj = dynamic_cast(self); + auto obj = dynamic_cast(self); assert(obj != nullptr); PyObject* capsule = obj->as_pybind11_tests_class_sh_void_ptr_capsule_Valid(); return pybind11::reinterpret_steal(capsule); @@ -122,7 +123,7 @@ TEST_SUBMODULE(class_sh_void_ptr_capsule, m) { .def(py::init<>()) .def("as_pybind11_tests_class_sh_void_ptr_capsule_NoCapsuleReturned", [](HelperBase* self) { - NoCapsuleReturned *obj = dynamic_cast(self); + auto obj = dynamic_cast(self); assert(obj != nullptr); PyObject* capsule = obj->as_pybind11_tests_class_sh_void_ptr_capsule_NoCapsuleReturned(); return pybind11::reinterpret_steal(capsule); @@ -132,7 +133,7 @@ TEST_SUBMODULE(class_sh_void_ptr_capsule, m) { .def(py::init<>()) .def("as_pybind11_tests_class_sh_void_ptr_capsule_Valid", [](HelperBase* self) { - AsAnotherObject *obj = dynamic_cast(self); + auto obj = dynamic_cast(self); assert(obj != nullptr); PyObject* capsule = obj->as_pybind11_tests_class_sh_void_ptr_capsule_Valid(); return pybind11::reinterpret_steal(capsule);