Skip to content

Commit 68cbae6

Browse files
authored
tests: add or delete copy/move ctors where needed to make type traits match reality (#5833)
1 parent a6581ee commit 68cbae6

11 files changed

+19
-1
lines changed

tests/test_buffers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ TEST_SUBMODULE(buffers, m) {
227227
+ std::to_string(cols) + "(*" + std::to_string(col_factor)
228228
+ ") matrix");
229229
}
230-
230+
DiscontiguousMatrix(const DiscontiguousMatrix &) = delete;
231231
~DiscontiguousMatrix() {
232232
print_destroyed(this,
233233
std::to_string(rows() / m_row_factor) + "(*"

tests/test_class.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ TEST_SUBMODULE(class_, m) {
521521
// test_exception_rvalue_abort
522522
struct PyPrintDestructor {
523523
PyPrintDestructor() = default;
524+
PyPrintDestructor(const PyPrintDestructor &) = default;
524525
~PyPrintDestructor() { py::print("Print from destructor"); }
525526
void throw_something() { throw std::runtime_error("error"); }
526527
};

tests/test_class_release_gil_before_calling_cpp_dtor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct ProbeType {
2222

2323
public:
2424
explicit ProbeType(const std::string &unique_key) : unique_key{unique_key} {}
25+
ProbeType(const ProbeType &) = default;
2526

2627
~ProbeType() {
2728
RegistryType &reg = PyGILState_Check_Results();

tests/test_class_sh_property_non_owning.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ struct DataFieldsHolder {
3333
}
3434
}
3535

36+
DataFieldsHolder(DataFieldsHolder &&) noexcept = default;
37+
3638
DataField *vec_at(std::size_t index) {
3739
if (index >= vec.size()) {
3840
return nullptr;

tests/test_cross_module_rtti/lib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ __pragma(warning(disable : 4251))
1212
class TEST_CROSS_MODULE_RTTI_LIB_EXPORT Base : public std::enable_shared_from_this<Base> {
1313
public:
1414
Base(int a, int b);
15+
Base(const Base &) = default;
1516
virtual ~Base() = default;
1617

1718
virtual int get() const;

tests/test_eigen_matrix.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ TEST_SUBMODULE(eigen_matrix, m) {
237237

238238
public:
239239
ReturnTester() { print_created(this); }
240+
ReturnTester(const ReturnTester &) = default;
240241
~ReturnTester() { print_destroyed(this); }
241242
static Eigen::MatrixXd create() { return Eigen::MatrixXd::Ones(10, 10); }
242243
// NOLINTNEXTLINE(readability-const-return-type)

tests/test_numpy_array.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ TEST_SUBMODULE(numpy_array, sm) {
282282
struct ArrayClass {
283283
int data[2] = {1, 2};
284284
ArrayClass() { py::print("ArrayClass()"); }
285+
ArrayClass(const ArrayClass &) = default;
285286
~ArrayClass() { py::print("~ArrayClass()"); }
286287
};
287288
py::class_<ArrayClass>(sm, "ArrayClass")

tests/test_potentially_slicing_weak_ptr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ namespace potentially_slicing_weak_ptr {
1111

1212
template <int> // Using int as a trick to easily generate multiple types.
1313
struct VirtBase {
14+
VirtBase() = default;
1415
virtual ~VirtBase() = default;
16+
VirtBase(const VirtBase &) = delete;
1517
virtual int get_code() { return 100; }
1618
};
1719

tests/test_smart_ptr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ class MyObject4a {
161161
print_created(this);
162162
pointer_set<MyObject4a>().insert(this);
163163
};
164+
MyObject4a(const MyObject4a &) = delete;
165+
164166
int value;
165167

166168
static void cleanupAllInstances() {
@@ -182,13 +184,15 @@ class MyObject4a {
182184
class MyObject4b : public MyObject4a {
183185
public:
184186
explicit MyObject4b(int i) : MyObject4a(i) { print_created(this); }
187+
MyObject4b(const MyObject4b &) = delete;
185188
~MyObject4b() override { print_destroyed(this); }
186189
};
187190

188191
// test_large_holder
189192
class MyObject5 { // managed by huge_unique_ptr
190193
public:
191194
explicit MyObject5(int value) : value{value} { print_created(this); }
195+
MyObject5(const MyObject5 &) = delete;
192196
~MyObject5() { print_destroyed(this); }
193197
int value;
194198
};
@@ -245,6 +249,7 @@ struct SharedFromThisVirt : virtual SharedFromThisVBase {};
245249
// test_move_only_holder
246250
struct C {
247251
C() { print_created(this); }
252+
C(const C &) = delete;
248253
~C() { print_destroyed(this); }
249254
};
250255

@@ -265,6 +270,7 @@ struct TypeForHolderWithAddressOf {
265270
// test_move_only_holder_with_addressof_operator
266271
struct TypeForMoveOnlyHolderWithAddressOf {
267272
explicit TypeForMoveOnlyHolderWithAddressOf(int value) : value{value} { print_created(this); }
273+
TypeForMoveOnlyHolderWithAddressOf(const TypeForMoveOnlyHolderWithAddressOf &) = delete;
268274
~TypeForMoveOnlyHolderWithAddressOf() { print_destroyed(this); }
269275
std::string toString() const {
270276
return "MoveOnlyHolderWithAddressOf[" + std::to_string(value) + "]";

tests/test_stl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class OptionalProperties {
9999
using OptionalEnumValue = OptionalImpl<EnumType>;
100100

101101
OptionalProperties() : value(EnumType::kSet) {}
102+
OptionalProperties(const OptionalProperties &) = default;
102103
~OptionalProperties() {
103104
// Reset value to detect use-after-destruction.
104105
// This is set to a specific value rather than nullopt to ensure that

0 commit comments

Comments
 (0)