Skip to content

Commit ec557ff

Browse files
authored
Backport non-functional test_class_sh_*.cpp changes from PR #5213: 1. To avoid compiler warnings for unused code in the unnamed namespace. 2. To avoid clang-format changes. (#5258)
1 parent 51a968c commit ec557ff

7 files changed

+62
-41
lines changed

tests/test_class_sh_shared_ptr_copy_move.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,37 +50,38 @@ PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::FooSmHld)
5050
namespace pybind11_tests {
5151

5252
TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) {
53+
#if true // Trick to avoid clang-format changes, in support of PR #5213.
5354
namespace py = pybind11;
5455

5556
py::class_<FooShPtr, std::shared_ptr<FooShPtr>>(m, "FooShPtr")
5657
.def("get_history", &FooShPtr::get_history);
5758
py::classh<FooSmHld>(m, "FooSmHld").def("get_history", &FooSmHld::get_history);
5859

5960
auto outer = py::class_<Outer>(m, "Outer").def(py::init());
60-
#define MAKE_PROP(PropTyp) \
61-
MAKE_PROP_FOO(ShPtr, PropTyp) \
62-
MAKE_PROP_FOO(SmHld, PropTyp)
63-
64-
#define MAKE_PROP_FOO(FooTyp, PropTyp) \
65-
.def_##PropTyp(#FooTyp "_" #PropTyp "_default", &Outer::FooTyp) \
66-
.def_##PropTyp( \
67-
#FooTyp "_" #PropTyp "_copy", &Outer::FooTyp, py::return_value_policy::copy) \
68-
.def_##PropTyp( \
69-
#FooTyp "_" #PropTyp "_move", &Outer::FooTyp, py::return_value_policy::move)
61+
# define MAKE_PROP(PropTyp) \
62+
MAKE_PROP_FOO(ShPtr, PropTyp) \
63+
MAKE_PROP_FOO(SmHld, PropTyp)
64+
65+
# define MAKE_PROP_FOO(FooTyp, PropTyp) \
66+
.def_##PropTyp(#FooTyp "_" #PropTyp "_default", &Outer::FooTyp) \
67+
.def_##PropTyp( \
68+
#FooTyp "_" #PropTyp "_copy", &Outer::FooTyp, py::return_value_policy::copy) \
69+
.def_##PropTyp( \
70+
#FooTyp "_" #PropTyp "_move", &Outer::FooTyp, py::return_value_policy::move)
7071
outer MAKE_PROP(readonly) MAKE_PROP(readwrite);
71-
#undef MAKE_PROP_FOO
72-
73-
#define MAKE_PROP_FOO(FooTyp, PropTyp) \
74-
.def_##PropTyp(#FooTyp "_property_" #PropTyp "_default", &Outer::FooTyp) \
75-
.def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_copy", \
76-
&Outer::get##FooTyp, \
77-
py::return_value_policy::copy) \
78-
.def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_move", \
79-
&Outer::get##FooTyp, \
80-
py::return_value_policy::move)
72+
# undef MAKE_PROP_FOO
73+
74+
# define MAKE_PROP_FOO(FooTyp, PropTyp) \
75+
.def_##PropTyp(#FooTyp "_property_" #PropTyp "_default", &Outer::FooTyp) \
76+
.def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_copy", \
77+
&Outer::get##FooTyp, \
78+
py::return_value_policy::copy) \
79+
.def_property_##PropTyp(#FooTyp "_property_" #PropTyp "_move", \
80+
&Outer::get##FooTyp, \
81+
py::return_value_policy::move)
8182
outer MAKE_PROP(readonly);
82-
#undef MAKE_PROP_FOO
83-
#undef MAKE_PROP
83+
# undef MAKE_PROP_FOO
84+
# undef MAKE_PROP
8485

8586
m.def("test_ShPtr_copy", []() {
8687
auto o = std::make_shared<FooShPtr>("copy");
@@ -107,6 +108,7 @@ TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) {
107108
l.append(std::move(o));
108109
return l;
109110
});
111+
#endif
110112
}
111113

112114
} // namespace pybind11_tests

tests/test_class_sh_trampoline_basic.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ void wrap(py::module_ m, const char *py_class_name) {
7676
} // namespace class_sh_trampoline_basic
7777
} // namespace pybind11_tests
7878

79-
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_trampoline_basic::Abase<0>)
80-
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_trampoline_basic::Abase<1>)
79+
using namespace pybind11_tests::class_sh_trampoline_basic;
80+
81+
PYBIND11_SMART_HOLDER_TYPE_CASTERS(Abase<0>)
82+
PYBIND11_SMART_HOLDER_TYPE_CASTERS(Abase<1>)
8183

8284
TEST_SUBMODULE(class_sh_trampoline_basic, m) {
83-
using namespace pybind11_tests::class_sh_trampoline_basic;
8485
wrap<0>(m, "Abase0");
8586
wrap<1>(m, "Abase1");
8687
}

tests/test_class_sh_trampoline_self_life_support.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#include <string>
1111
#include <utility>
1212

13-
namespace {
13+
namespace pybind11_tests {
14+
namespace class_sh_trampoline_self_life_support {
1415

1516
struct Big5 { // Also known as "rule of five".
1617
std::string history;
@@ -41,7 +42,10 @@ struct Big5Trampoline : Big5, py::trampoline_self_life_support {
4142
using Big5::Big5;
4243
};
4344

44-
} // namespace
45+
} // namespace class_sh_trampoline_self_life_support
46+
} // namespace pybind11_tests
47+
48+
using namespace pybind11_tests::class_sh_trampoline_self_life_support;
4549

4650
PYBIND11_SMART_HOLDER_TYPE_CASTERS(Big5)
4751

tests/test_class_sh_trampoline_shared_from_this.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include <memory>
99
#include <string>
1010

11-
namespace {
11+
namespace pybind11_tests {
12+
namespace class_sh_trampoline_shared_from_this {
1213

1314
struct Sft : std::enable_shared_from_this<Sft> {
1415
std::string history;
@@ -98,7 +99,10 @@ std::shared_ptr<Sft> make_pure_cpp_sft_shd_ptr(const std::string &history_seed)
9899

99100
std::shared_ptr<Sft> pass_through_shd_ptr(const std::shared_ptr<Sft> &obj) { return obj; }
100101

101-
} // namespace
102+
} // namespace class_sh_trampoline_shared_from_this
103+
} // namespace pybind11_tests
104+
105+
using namespace pybind11_tests::class_sh_trampoline_shared_from_this;
102106

103107
PYBIND11_SMART_HOLDER_TYPE_CASTERS(Sft)
104108
PYBIND11_SMART_HOLDER_TYPE_CASTERS(SftSharedPtrStash)

tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
#include <utility>
99

10-
namespace {
10+
namespace pybind11_tests {
11+
namespace class_sh_trampoline_shared_ptr_cpp_arg {
1112

1213
// For testing whether a python subclass of a C++ object dies when the
1314
// last python reference is lost
@@ -51,7 +52,10 @@ struct SpGoAwayTester {
5152
std::shared_ptr<SpGoAway> m_obj;
5253
};
5354

54-
} // namespace
55+
} // namespace class_sh_trampoline_shared_ptr_cpp_arg
56+
} // namespace pybind11_tests
57+
58+
using namespace pybind11_tests::class_sh_trampoline_shared_ptr_cpp_arg;
5559

5660
PYBIND11_SMART_HOLDER_TYPE_CASTERS(SpBase)
5761
PYBIND11_SMART_HOLDER_TYPE_CASTERS(SpBaseTester)

tests/test_class_sh_trampoline_unique_ptr.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
#include <cstdint>
1010

11-
namespace {
11+
namespace pybind11_tests {
12+
namespace class_sh_trampoline_unique_ptr {
1213

1314
class Class {
1415
public:
@@ -30,11 +31,13 @@ class Class {
3031
std::uint64_t val_ = 0;
3132
};
3233

33-
} // namespace
34+
} // namespace class_sh_trampoline_unique_ptr
35+
} // namespace pybind11_tests
3436

35-
PYBIND11_SMART_HOLDER_TYPE_CASTERS(Class)
37+
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_trampoline_unique_ptr::Class)
3638

37-
namespace {
39+
namespace pybind11_tests {
40+
namespace class_sh_trampoline_unique_ptr {
3841

3942
class PyClass : public Class, public py::trampoline_self_life_support {
4043
public:
@@ -45,9 +48,12 @@ class PyClass : public Class, public py::trampoline_self_life_support {
4548
int foo() const override { PYBIND11_OVERRIDE_PURE(int, Class, foo); }
4649
};
4750

48-
} // namespace
51+
} // namespace class_sh_trampoline_unique_ptr
52+
} // namespace pybind11_tests
4953

5054
TEST_SUBMODULE(class_sh_trampoline_unique_ptr, m) {
55+
using namespace pybind11_tests::class_sh_trampoline_unique_ptr;
56+
5157
py::classh<Class, PyClass>(m, "Class")
5258
.def(py::init<>())
5359
.def("set_val", &Class::setVal)

tests/test_class_sh_virtual_py_cpp_mix.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ struct CppDerivedVirtualOverrider : CppDerived, py::trampoline_self_life_support
4646
} // namespace class_sh_virtual_py_cpp_mix
4747
} // namespace pybind11_tests
4848

49-
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_virtual_py_cpp_mix::Base)
50-
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_virtual_py_cpp_mix::CppDerivedPlain)
51-
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_virtual_py_cpp_mix::CppDerived)
49+
using namespace pybind11_tests::class_sh_virtual_py_cpp_mix;
5250

53-
TEST_SUBMODULE(class_sh_virtual_py_cpp_mix, m) {
54-
using namespace pybind11_tests::class_sh_virtual_py_cpp_mix;
51+
PYBIND11_SMART_HOLDER_TYPE_CASTERS(Base)
52+
PYBIND11_SMART_HOLDER_TYPE_CASTERS(CppDerivedPlain)
53+
PYBIND11_SMART_HOLDER_TYPE_CASTERS(CppDerived)
5554

55+
TEST_SUBMODULE(class_sh_virtual_py_cpp_mix, m) {
5656
py::classh<Base, BaseVirtualOverrider>(m, "Base").def(py::init<>()).def("get", &Base::get);
5757

5858
py::classh<CppDerivedPlain, Base>(m, "CppDerivedPlain").def(py::init<>());

0 commit comments

Comments
 (0)