Skip to content

Commit 8d1e0b3

Browse files
authored
[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.
1 parent 274b014 commit 8d1e0b3

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

.github/workflows/format.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ jobs:
4444
-DCMAKE_CXX_STANDARD=17
4545
4646
- name: Build
47-
run: cmake --build build -j 2
47+
run: cmake --build build -j 2 -- --keep-going

include/pybind11/detail/smart_holder_poc.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct smart_holder {
122122
vptr_is_external_shared_ptr{false}, is_populated{false}, is_disowned{false},
123123
pointee_depends_on_holder_owner{false} {}
124124

125-
bool has_pointee() const { return vptr.get() != nullptr; }
125+
bool has_pointee() const { return vptr != nullptr; }
126126

127127
template <typename T>
128128
static void ensure_pointee_is_destructible(const char *context) {
@@ -180,7 +180,7 @@ struct smart_holder {
180180
}
181181

182182
void ensure_use_count_1(const char *context) const {
183-
if (vptr.get() == nullptr) {
183+
if (vptr == nullptr) {
184184
throw std::invalid_argument(std::string("Cannot disown nullptr (") + context + ").");
185185
}
186186
// In multithreaded environments accessing use_count can lead to
@@ -194,7 +194,7 @@ struct smart_holder {
194194
}
195195
}
196196

197-
void reset_vptr_deleter_armed_flag(bool armed_flag) {
197+
void reset_vptr_deleter_armed_flag(bool armed_flag) const {
198198
auto vptr_del_ptr = std::get_deleter<guarded_delete>(vptr);
199199
if (vptr_del_ptr == nullptr) {
200200
throw std::runtime_error(
@@ -259,7 +259,7 @@ struct smart_holder {
259259
void release_disowned() { vptr.reset(); }
260260

261261
// SMART_HOLDER_WIP: review this function.
262-
void ensure_can_release_ownership(const char *context = "ensure_can_release_ownership") {
262+
void ensure_can_release_ownership(const char *context = "ensure_can_release_ownership") const {
263263
ensure_is_not_disowned(context);
264264
ensure_vptr_is_using_builtin_delete(context);
265265
ensure_use_count_1(context);

tests/test_class_sh_basic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct uconsumer { // unique_ptr consumer
2525
void pass_rref(std::unique_ptr<atyp> &&obj) { held = std::move(obj); }
2626
std::unique_ptr<atyp> rtrn_valu() { return std::move(held); }
2727
std::unique_ptr<atyp> &rtrn_lref() { return held; }
28-
const std::unique_ptr<atyp> &rtrn_cref() { return held; }
28+
const std::unique_ptr<atyp> &rtrn_cref() const { return held; }
2929
};
3030

3131
// clang-format off

tests/test_class_sh_disowning_mi.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ void disown_b(std::unique_ptr<B>) {}
3232
// test_multiple_inheritance_python
3333
struct Base1 {
3434
Base1(int i) : i(i) {}
35-
int foo() { return i; }
35+
int foo() const { return i; }
3636
int i;
3737
};
3838

3939
struct Base2 {
4040
Base2(int j) : j(j) {}
41-
int bar() { return j; }
41+
int bar() const { return j; }
4242
int j;
4343
};
4444

tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct PySpBase : SpBase {
2929
};
3030

3131
struct SpBaseTester {
32-
std::shared_ptr<SpBase> get_object() { return m_obj; }
32+
std::shared_ptr<SpBase> get_object() const { return m_obj; }
3333
void set_object(std::shared_ptr<SpBase> obj) { m_obj = obj; }
3434
bool is_base_used() { return m_obj->is_base_used(); }
3535
bool has_instance() { return (bool)m_obj; }

0 commit comments

Comments
 (0)