[smart_holder] clang-tidy fixes (related to recent clang-tidy changes on master). (#3053)

* clang-tidy fixes (related to recent clang-tidy changes on master).

* More clang-tidy fixes.
This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-06-21 12:40:10 -07:00 committed by GitHub
parent 274b014578
commit 8d1e0b3903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 9 deletions

View File

@ -44,4 +44,4 @@ jobs:
-DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD=17
- name: Build - name: Build
run: cmake --build build -j 2 run: cmake --build build -j 2 -- --keep-going

View File

@ -122,7 +122,7 @@ struct smart_holder {
vptr_is_external_shared_ptr{false}, is_populated{false}, is_disowned{false}, vptr_is_external_shared_ptr{false}, is_populated{false}, is_disowned{false},
pointee_depends_on_holder_owner{false} {} pointee_depends_on_holder_owner{false} {}
bool has_pointee() const { return vptr.get() != nullptr; } bool has_pointee() const { return vptr != nullptr; }
template <typename T> template <typename T>
static void ensure_pointee_is_destructible(const char *context) { 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 { 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 + ")."); throw std::invalid_argument(std::string("Cannot disown nullptr (") + context + ").");
} }
// In multithreaded environments accessing use_count can lead to // 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<guarded_delete>(vptr); auto vptr_del_ptr = std::get_deleter<guarded_delete>(vptr);
if (vptr_del_ptr == nullptr) { if (vptr_del_ptr == nullptr) {
throw std::runtime_error( throw std::runtime_error(
@ -259,7 +259,7 @@ struct smart_holder {
void release_disowned() { vptr.reset(); } void release_disowned() { vptr.reset(); }
// SMART_HOLDER_WIP: review this function. // 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_is_not_disowned(context);
ensure_vptr_is_using_builtin_delete(context); ensure_vptr_is_using_builtin_delete(context);
ensure_use_count_1(context); ensure_use_count_1(context);

View File

@ -25,7 +25,7 @@ struct uconsumer { // unique_ptr consumer
void pass_rref(std::unique_ptr<atyp> &&obj) { held = std::move(obj); } void pass_rref(std::unique_ptr<atyp> &&obj) { held = std::move(obj); }
std::unique_ptr<atyp> rtrn_valu() { return std::move(held); } std::unique_ptr<atyp> rtrn_valu() { return std::move(held); }
std::unique_ptr<atyp> &rtrn_lref() { return held; } std::unique_ptr<atyp> &rtrn_lref() { return held; }
const std::unique_ptr<atyp> &rtrn_cref() { return held; } const std::unique_ptr<atyp> &rtrn_cref() const { return held; }
}; };
// clang-format off // clang-format off

View File

@ -32,13 +32,13 @@ void disown_b(std::unique_ptr<B>) {}
// test_multiple_inheritance_python // test_multiple_inheritance_python
struct Base1 { struct Base1 {
Base1(int i) : i(i) {} Base1(int i) : i(i) {}
int foo() { return i; } int foo() const { return i; }
int i; int i;
}; };
struct Base2 { struct Base2 {
Base2(int j) : j(j) {} Base2(int j) : j(j) {}
int bar() { return j; } int bar() const { return j; }
int j; int j;
}; };

View File

@ -29,7 +29,7 @@ struct PySpBase : SpBase {
}; };
struct SpBaseTester { struct SpBaseTester {
std::shared_ptr<SpBase> get_object() { return m_obj; } std::shared_ptr<SpBase> get_object() const { return m_obj; }
void set_object(std::shared_ptr<SpBase> obj) { m_obj = obj; } void set_object(std::shared_ptr<SpBase> obj) { m_obj = obj; }
bool is_base_used() { return m_obj->is_base_used(); } bool is_base_used() { return m_obj->is_base_used(); }
bool has_instance() { return (bool)m_obj; } bool has_instance() { return (bool)m_obj; }