From 22af7e370f44d589a42697114c64fdafcd5e5e6c Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 23 Feb 2023 13:15:17 -0800 Subject: [PATCH 1/2] Avoid warning C5267. --- stl/inc/bitset | 2 ++ tests/std/tests/Dev08_576265_list_remove/test.cpp | 2 ++ .../tests/Dev11_0437519_container_behavior/test.cpp | 2 ++ .../test.cpp | 2 ++ tests/std/tests/P0220R1_any/test.cpp | 6 ++++++ tests/std/tests/P0220R1_optional/test.cpp | 11 +++++++++++ .../test.cpp | 1 - .../std/tests/P0674R1_make_shared_for_arrays/test.cpp | 4 ++++ .../test.cpp | 8 ++++++-- tests/std/tests/P0896R4_views_join/test.cpp | 7 +++++++ .../test.cpp | 2 ++ 11 files changed, 44 insertions(+), 3 deletions(-) diff --git a/stl/inc/bitset b/stl/inc/bitset index e90b1c5c3cd..6c126b9975f 100644 --- a/stl/inc/bitset +++ b/stl/inc/bitset @@ -32,6 +32,8 @@ public: friend bitset<_Bits>; public: + _CONSTEXPR23 reference(const reference&) noexcept = default; + _CONSTEXPR23 ~reference() noexcept {} // TRANSITION, ABI _CONSTEXPR23 reference& operator=(const bool _Val) noexcept { diff --git a/tests/std/tests/Dev08_576265_list_remove/test.cpp b/tests/std/tests/Dev08_576265_list_remove/test.cpp index f941f74ebd2..2a4a7785932 100644 --- a/tests/std/tests/Dev08_576265_list_remove/test.cpp +++ b/tests/std/tests/Dev08_576265_list_remove/test.cpp @@ -9,6 +9,8 @@ struct Val { unsigned int canary; Val() : value(0), canary(0xDEADBEEF) {} Val(int val) : value(val), canary(0x600DF00D) {} + Val(const Val&) = default; + Val& operator=(const Val&) = default; ~Val() { canary = 0xDEADBEEF; } diff --git a/tests/std/tests/Dev11_0437519_container_behavior/test.cpp b/tests/std/tests/Dev11_0437519_container_behavior/test.cpp index 8a6e1f238dd..9dcdd7d8c37 100644 --- a/tests/std/tests/Dev11_0437519_container_behavior/test.cpp +++ b/tests/std/tests/Dev11_0437519_container_behavior/test.cpp @@ -23,6 +23,8 @@ void assert_forward_list_resize_empty() { struct A { A(unsigned int value) : _value(value) {} + A(const A&) = default; + A& operator=(const A&) = default; ~A() { _value = 0; } diff --git a/tests/std/tests/GH_002488_promise_not_default_constructible_types/test.cpp b/tests/std/tests/GH_002488_promise_not_default_constructible_types/test.cpp index 35a7b92db0c..1aafc7bfa90 100644 --- a/tests/std/tests/GH_002488_promise_not_default_constructible_types/test.cpp +++ b/tests/std/tests/GH_002488_promise_not_default_constructible_types/test.cpp @@ -22,6 +22,7 @@ struct has_default { has_default(const has_default& v) : x(v.x) { ++has_default_objects; } + has_default& operator=(const has_default&) = default; ~has_default() { --has_default_objects; @@ -38,6 +39,7 @@ struct no_default { no_default(const no_default& v) : x(v.x) { ++no_default_objects; } + no_default& operator=(const no_default&) = default; ~no_default() { --no_default_objects; diff --git a/tests/std/tests/P0220R1_any/test.cpp b/tests/std/tests/P0220R1_any/test.cpp index 5fccb41c847..b65c7332cdd 100644 --- a/tests/std/tests/P0220R1_any/test.cpp +++ b/tests/std/tests/P0220R1_any/test.cpp @@ -1211,6 +1211,8 @@ namespace modifiers::emplace { struct Tracked { static int count; Tracked() {++count;} + Tracked(const Tracked&) noexcept {++count;} + Tracked& operator=(const Tracked&) = default; ~Tracked() { --count; } }; int Tracked::count = 0; @@ -2976,6 +2978,10 @@ namespace msvc { Tracked() { ++count; } + Tracked(const Tracked&) noexcept { + ++count; + } + Tracked& operator=(const Tracked&) = default; ~Tracked() { --count; } diff --git a/tests/std/tests/P0220R1_optional/test.cpp b/tests/std/tests/P0220R1_optional/test.cpp index 33644626f10..77d3497fde1 100644 --- a/tests/std/tests/P0220R1_optional/test.cpp +++ b/tests/std/tests/P0220R1_optional/test.cpp @@ -2372,6 +2372,8 @@ class Y static bool dtor_called; Y() = default; Y(int) { TEST_THROW(6);} + Y(const Y&) = default; + Y& operator=(const Y&) = default; ~Y() {dtor_called = true;} }; @@ -2659,6 +2661,8 @@ class X constexpr X(int i, bool& dtor_called) : i_(i), dtor_called_(&dtor_called) {} constexpr X(std::initializer_list il, bool& dtor_called) : i_(il.begin()[0]), j_(il.begin()[1]), dtor_called_(&dtor_called) {} + X(const X&) = default; + X& operator=(const X&) = default; TEST_CONSTEXPR_CXX20 ~X() {*dtor_called_ = true;} friend constexpr bool operator==(const X& x, const X& y) @@ -2688,6 +2692,8 @@ class Z Z(int i) : i_(i) {} Z(std::initializer_list il) : i_(il.begin()[0]), j_(il.begin()[1]) { TEST_THROW(6);} + Z(const Z&) = default; + Z& operator=(const Z&) = default; ~Z() {dtor_called = true;} friend bool operator==(const Z& x, const Z& y) @@ -5336,6 +5342,8 @@ class X public: static bool dtor_called; X() = default; + X(const X&) = default; + X& operator=(const X&) = default; ~X() {dtor_called = true;} }; @@ -5401,6 +5409,9 @@ using std::optional; struct X { static bool dtor_called; + X() = default; + X(const X&) = default; + X& operator=(const X&) = default; ~X() {dtor_called = true;} }; diff --git a/tests/std/tests/P0608R3_improved_variant_converting_constructor/test.cpp b/tests/std/tests/P0608R3_improved_variant_converting_constructor/test.cpp index b5f1f734c79..38e604d1b7c 100644 --- a/tests/std/tests/P0608R3_improved_variant_converting_constructor/test.cpp +++ b/tests/std/tests/P0608R3_improved_variant_converting_constructor/test.cpp @@ -21,7 +21,6 @@ struct double_double { }; struct convertible_bool { convertible_bool(bool x) : x_(x) {} - ~convertible_bool() = default; operator bool() const noexcept { return x_; diff --git a/tests/std/tests/P0674R1_make_shared_for_arrays/test.cpp b/tests/std/tests/P0674R1_make_shared_for_arrays/test.cpp index dcc63a93d2f..b952a9a69f4 100644 --- a/tests/std/tests/P0674R1_make_shared_for_arrays/test.cpp +++ b/tests/std/tests/P0674R1_make_shared_for_arrays/test.cpp @@ -643,6 +643,10 @@ struct WeirdDeleter { delete ptr; } + WeirdDeleter() = default; + WeirdDeleter(const WeirdDeleter&) = default; + WeirdDeleter& operator=(const WeirdDeleter&) = default; + ~WeirdDeleter() noexcept(false) {} }; static_assert(!is_nothrow_destructible_v>); diff --git a/tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp b/tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp index 57c64806081..4f7aa4dcdad 100644 --- a/tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp +++ b/tests/std/tests/P0784R7_library_support_for_more_constexpr_containers/test.cpp @@ -263,8 +263,10 @@ template struct A { T value; - constexpr A() noexcept = default; - constexpr ~A() = default; + constexpr A() noexcept = default; + constexpr A(const A&) noexcept = default; + constexpr A& operator=(const A&) noexcept = default; + constexpr ~A() = default; }; template @@ -272,6 +274,8 @@ struct nontrivial_A { T value; constexpr nontrivial_A(T in = T{}) noexcept : value(in) {} + constexpr nontrivial_A(const nontrivial_A&) noexcept = default; + constexpr nontrivial_A& operator=(const nontrivial_A&) noexcept = default; constexpr ~nontrivial_A() {} }; diff --git a/tests/std/tests/P0896R4_views_join/test.cpp b/tests/std/tests/P0896R4_views_join/test.cpp index 7da95ce34bc..bc5bd9d641d 100644 --- a/tests/std/tests/P0896R4_views_join/test.cpp +++ b/tests/std/tests/P0896R4_views_join/test.cpp @@ -477,6 +477,13 @@ void test_non_trivially_destructible_type() { // COMPILE-ONLY using difference_type = int; using value_type = int; + // Provide some way to construct this type. + non_trivially_destructible_input_iterator(double, double) {} + + non_trivially_destructible_input_iterator(const non_trivially_destructible_input_iterator&) = default; + non_trivially_destructible_input_iterator& operator=( + const non_trivially_destructible_input_iterator&) = default; + ~non_trivially_destructible_input_iterator() {} // To test the correct specialization of _Defaultabox, this type must not be default constructible. diff --git a/tests/std/tests/P2231R1_complete_constexpr_optional_variant/test.cpp b/tests/std/tests/P2231R1_complete_constexpr_optional_variant/test.cpp index 77ab2d93b01..d87f42baaa2 100644 --- a/tests/std/tests/P2231R1_complete_constexpr_optional_variant/test.cpp +++ b/tests/std/tests/P2231R1_complete_constexpr_optional_variant/test.cpp @@ -24,6 +24,8 @@ struct With_nontrivial_destructor { int _val = 0; constexpr With_nontrivial_destructor(const int val) noexcept : _val(val) {} constexpr With_nontrivial_destructor(initializer_list vals) noexcept : _val(*vals.begin()) {} + With_nontrivial_destructor(const With_nontrivial_destructor&) = default; + With_nontrivial_destructor& operator=(const With_nontrivial_destructor&) = default; constexpr ~With_nontrivial_destructor() {} constexpr bool operator==(const int right) const noexcept { From 54eb6e314f6f1ee9041832f7f28a8ad7a9a8f65b Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 23 Feb 2023 22:36:41 -0800 Subject: [PATCH 2/2] Code review feedback. --- stl/inc/bitset | 12 ++++++------ tests/std/tests/P0220R1_any/test.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/stl/inc/bitset b/stl/inc/bitset index 6c126b9975f..0edffa4ee4c 100644 --- a/stl/inc/bitset +++ b/stl/inc/bitset @@ -32,7 +32,7 @@ public: friend bitset<_Bits>; public: - _CONSTEXPR23 reference(const reference&) noexcept = default; + _CONSTEXPR23 reference(const reference&) = default; _CONSTEXPR23 ~reference() noexcept {} // TRANSITION, ABI @@ -46,11 +46,6 @@ public: return *this; } - _CONSTEXPR23 reference& flip() noexcept { - _Pbitset->_Flip_unchecked(_Mypos); - return *this; - } - _NODISCARD _CONSTEXPR23 bool operator~() const noexcept { return !_Pbitset->_Subscript(_Mypos); } @@ -59,6 +54,11 @@ public: return _Pbitset->_Subscript(_Mypos); } + _CONSTEXPR23 reference& flip() noexcept { + _Pbitset->_Flip_unchecked(_Mypos); + return *this; + } + private: _CONSTEXPR23 reference() noexcept : _Pbitset(nullptr), _Mypos(0) {} diff --git a/tests/std/tests/P0220R1_any/test.cpp b/tests/std/tests/P0220R1_any/test.cpp index b65c7332cdd..cd69a914de5 100644 --- a/tests/std/tests/P0220R1_any/test.cpp +++ b/tests/std/tests/P0220R1_any/test.cpp @@ -1211,8 +1211,8 @@ namespace modifiers::emplace { struct Tracked { static int count; Tracked() {++count;} - Tracked(const Tracked&) noexcept {++count;} - Tracked& operator=(const Tracked&) = default; + Tracked(Tracked const&) noexcept {++count;} + Tracked& operator=(Tracked const&) = default; ~Tracked() { --count; } }; int Tracked::count = 0; @@ -2978,10 +2978,10 @@ namespace msvc { Tracked() { ++count; } - Tracked(const Tracked&) noexcept { + Tracked(Tracked const&) noexcept { ++count; } - Tracked& operator=(const Tracked&) = default; + Tracked& operator=(Tracked const&) = default; ~Tracked() { --count; }