Skip to content

Commit b4e1ac9

Browse files
committed
clang-tidy fixes related to PR #3250
1 parent 94a5c67 commit b4e1ac9

8 files changed

+19
-11
lines changed

.codespell-ignorelines

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
assert m.atyp_valu().get_mtxt() == "Valu"
22
atyp_valu rtrn_valu() { atyp_valu obj{"Valu"}; return obj; }
3-
indestructible_int(int v) : valu{v} {}
3+
explicit indestructible_int(int v) : valu{v} {}
4+
explicit movable_int(int v) : valu{v} {}
45
int valu;
5-
movable_int(int v) : valu{v} {}
66
(m.pass_valu, "Valu", "pass_valu:Valu(_MvCtor)*_CpCtor"),
77
other.valu = 91;
88
REQUIRE(hld.as_raw_ptr_unowned<zombie>()->valu == 19);

include/pybind11/detail/smart_holder_type_casters.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ inline bool deregister_instance(instance *self, void *valptr, const type_info *t
4343
// clang-format off
4444
class modified_type_caster_generic_load_impl {
4545
public:
46-
PYBIND11_NOINLINE modified_type_caster_generic_load_impl(const std::type_info &type_info)
46+
PYBIND11_NOINLINE explicit modified_type_caster_generic_load_impl(const std::type_info &type_info)
4747
: typeinfo(get_type_info(type_info)), cpptype(&type_info) { }
4848

4949
explicit modified_type_caster_generic_load_impl(const type_info *typeinfo = nullptr)
@@ -598,13 +598,17 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
598598
// The const operators here prove that the existing type_caster mechanism already supports
599599
// const-correctness. However, fully implementing const-correctness inside this type_caster
600600
// is still a major project.
601+
// NOLINTNEXTLINE(google-explicit-constructor)
601602
operator T const &() const {
602603
return const_cast<smart_holder_type_caster *>(this)->loaded_as_lvalue_ref();
603604
}
605+
// NOLINTNEXTLINE(google-explicit-constructor)
604606
operator T const *() const {
605607
return const_cast<smart_holder_type_caster *>(this)->loaded_as_raw_ptr_unowned();
606608
}
609+
// NOLINTNEXTLINE(google-explicit-constructor)
607610
operator T &() { return this->loaded_as_lvalue_ref(); }
611+
// NOLINTNEXTLINE(google-explicit-constructor)
608612
operator T *() { return this->loaded_as_raw_ptr_unowned(); }
609613

610614
// Originally type_caster_generic::cast.
@@ -749,6 +753,7 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
749753
template <typename>
750754
using cast_op_type = std::shared_ptr<T>;
751755

756+
// NOLINTNEXTLINE(google-explicit-constructor)
752757
operator std::shared_ptr<T>() { return this->loaded_as_shared_ptr(); }
753758
};
754759

@@ -768,6 +773,7 @@ struct smart_holder_type_caster<std::shared_ptr<T const>> : smart_holder_type_ca
768773
template <typename>
769774
using cast_op_type = std::shared_ptr<T const>;
770775

776+
// NOLINTNEXTLINE(google-explicit-constructor)
771777
operator std::shared_ptr<T const>() { return this->loaded_as_shared_ptr(); } // Mutbl2Const
772778
};
773779

@@ -844,6 +850,7 @@ struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caste
844850
template <typename>
845851
using cast_op_type = std::unique_ptr<T, D>;
846852

853+
// NOLINTNEXTLINE(google-explicit-constructor)
847854
operator std::unique_ptr<T, D>() { return this->template loaded_as_unique_ptr<D>(); }
848855
};
849856

@@ -863,6 +870,7 @@ struct smart_holder_type_caster<std::unique_ptr<T const, D>>
863870
template <typename>
864871
using cast_op_type = std::unique_ptr<T const, D>;
865872

873+
// NOLINTNEXTLINE(google-explicit-constructor)
866874
operator std::unique_ptr<T const, D>() { return this->template loaded_as_unique_ptr<D>(); }
867875
};
868876

tests/pure_cpp/smart_holder_poc_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace helpers {
99

1010
struct movable_int {
1111
int valu;
12-
movable_int(int v) : valu{v} {}
12+
explicit movable_int(int v) : valu{v} {}
1313
movable_int(movable_int &&other) noexcept {
1414
valu = other.valu;
1515
other.valu = 91;
@@ -26,7 +26,7 @@ struct functor_other_delete : functor_builtin_delete<T> {};
2626

2727
struct indestructible_int {
2828
int valu;
29-
indestructible_int(int v) : valu{v} {}
29+
explicit indestructible_int(int v) : valu{v} {}
3030

3131
private:
3232
~indestructible_int() = default;

tests/test_class_sh_basic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace class_sh_basic {
1212
struct atyp { // Short for "any type".
1313
std::string mtxt;
1414
atyp() : mtxt("DefaultConstructor") {}
15-
atyp(const std::string &mtxt_) : mtxt(mtxt_) {}
15+
explicit atyp(const std::string &mtxt_) : mtxt(mtxt_) {}
1616
atyp(const atyp &other) { mtxt = other.mtxt + "_CpCtor"; }
1717
atyp(atyp &&other) noexcept { mtxt = other.mtxt + "_MvCtor"; }
1818
};

tests/test_class_sh_disowning.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace class_sh_disowning {
1010
template <int SerNo> // Using int as a trick to easily generate a series of types.
1111
struct Atype {
1212
int val = 0;
13-
Atype(int val_) : val{val_} {}
13+
explicit Atype(int val_) : val{val_} {}
1414
int get() const { return val * 10 + SerNo; }
1515
};
1616

tests/test_class_sh_disowning_mi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ void disown_b(std::unique_ptr<B>) {}
3131

3232
// test_multiple_inheritance_python
3333
struct Base1 {
34-
Base1(int i) : i(i) {}
34+
explicit Base1(int i) : i(i) {}
3535
int foo() const { return i; }
3636
int i;
3737
};
3838

3939
struct Base2 {
40-
Base2(int j) : j(j) {}
40+
explicit Base2(int j) : j(j) {}
4141
int bar() const { return j; }
4242
int j;
4343
};

tests/test_class_sh_shared_ptr_copy_move.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const std::string fooNames[] = {"ShPtr_", "SmHld_"};
1414
template <int SerNo>
1515
struct Foo {
1616
std::string history;
17-
Foo(const std::string &history_) : history(history_) {}
17+
explicit Foo(const std::string &history_) : history(history_) {}
1818
Foo(const Foo &other) : history(other.history + "_CpCtor") {}
1919
Foo(Foo &&other) noexcept : history(other.history + "_MvCtor") {}
2020
Foo &operator=(const Foo &other) {

tests/test_class_sh_trampoline_basic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ template <int SerNo> // Using int as a trick to easily generate a series of type
1111
struct Abase {
1212
int val = 0;
1313
virtual ~Abase() = default;
14-
Abase(int val_) : val{val_} {}
14+
explicit Abase(int val_) : val{val_} {}
1515
int Get() const { return val * 10 + 3; }
1616
virtual int Add(int other_val) const = 0;
1717

0 commit comments

Comments
 (0)