From a4558c32e6c0ab4d11c8fcde5d87b34574d4cac7 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 21 Jun 2021 10:06:34 -0700 Subject: [PATCH 1/2] clang-tidy fixes (related to recent clang-tidy changes on master). --- .github/workflows/format.yml | 2 +- include/pybind11/detail/smart_holder_poc.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index c856da6888..ac6d61aaed 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -44,4 +44,4 @@ jobs: -DCMAKE_CXX_STANDARD=17 - name: Build - run: cmake --build build -j 2 + run: cmake --build build -j 2 -- --keep-going diff --git a/include/pybind11/detail/smart_holder_poc.h b/include/pybind11/detail/smart_holder_poc.h index 4df9b42fb5..d8ecf149d5 100644 --- a/include/pybind11/detail/smart_holder_poc.h +++ b/include/pybind11/detail/smart_holder_poc.h @@ -122,7 +122,7 @@ struct smart_holder { vptr_is_external_shared_ptr{false}, is_populated{false}, is_disowned{false}, pointee_depends_on_holder_owner{false} {} - bool has_pointee() const { return vptr.get() != nullptr; } + bool has_pointee() const { return vptr != nullptr; } template static void ensure_pointee_is_destructible(const char *context) { @@ -180,7 +180,7 @@ struct smart_holder { } void ensure_use_count_1(const char *context) const { - if (vptr.get() == nullptr) { + if (vptr == nullptr) { throw std::invalid_argument(std::string("Cannot disown nullptr (") + context + ")."); } // In multithreaded environments accessing use_count can lead to @@ -194,7 +194,7 @@ struct smart_holder { } } - void reset_vptr_deleter_armed_flag(bool armed_flag) { + void reset_vptr_deleter_armed_flag(bool armed_flag) const { auto vptr_del_ptr = std::get_deleter(vptr); if (vptr_del_ptr == nullptr) { throw std::runtime_error( From aa4cfa3bef38efdb1ddb7722d7870d0cb40c5447 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 21 Jun 2021 11:55:00 -0700 Subject: [PATCH 2/2] More clang-tidy fixes. --- include/pybind11/detail/smart_holder_poc.h | 2 +- tests/test_class_sh_basic.cpp | 2 +- tests/test_class_sh_disowning_mi.cpp | 4 ++-- tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/pybind11/detail/smart_holder_poc.h b/include/pybind11/detail/smart_holder_poc.h index d8ecf149d5..36c873dce6 100644 --- a/include/pybind11/detail/smart_holder_poc.h +++ b/include/pybind11/detail/smart_holder_poc.h @@ -259,7 +259,7 @@ struct smart_holder { void release_disowned() { vptr.reset(); } // SMART_HOLDER_WIP: review this function. - void ensure_can_release_ownership(const char *context = "ensure_can_release_ownership") { + void ensure_can_release_ownership(const char *context = "ensure_can_release_ownership") const { ensure_is_not_disowned(context); ensure_vptr_is_using_builtin_delete(context); ensure_use_count_1(context); diff --git a/tests/test_class_sh_basic.cpp b/tests/test_class_sh_basic.cpp index ff9f97607d..fb1de946e3 100644 --- a/tests/test_class_sh_basic.cpp +++ b/tests/test_class_sh_basic.cpp @@ -25,7 +25,7 @@ struct uconsumer { // unique_ptr consumer void pass_rref(std::unique_ptr &&obj) { held = std::move(obj); } std::unique_ptr rtrn_valu() { return std::move(held); } std::unique_ptr &rtrn_lref() { return held; } - const std::unique_ptr &rtrn_cref() { return held; } + const std::unique_ptr &rtrn_cref() const { return held; } }; // clang-format off diff --git a/tests/test_class_sh_disowning_mi.cpp b/tests/test_class_sh_disowning_mi.cpp index 1ccb5e4b03..1e7b1166ba 100644 --- a/tests/test_class_sh_disowning_mi.cpp +++ b/tests/test_class_sh_disowning_mi.cpp @@ -32,13 +32,13 @@ void disown_b(std::unique_ptr) {} // test_multiple_inheritance_python struct Base1 { Base1(int i) : i(i) {} - int foo() { return i; } + int foo() const { return i; } int i; }; struct Base2 { Base2(int j) : j(j) {} - int bar() { return j; } + int bar() const { return j; } int j; }; diff --git a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp index dfdbea18a6..b6e2517b47 100644 --- a/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp +++ b/tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp @@ -29,7 +29,7 @@ struct PySpBase : SpBase { }; struct SpBaseTester { - std::shared_ptr get_object() { return m_obj; } + std::shared_ptr get_object() const { return m_obj; } void set_object(std::shared_ptr obj) { m_obj = obj; } bool is_base_used() { return m_obj->is_base_used(); } bool has_instance() { return (bool)m_obj; }