You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Only generate other operator= functions from (out this, that) if _none_ of the other three were written - generate all of them or none of them
Remove the "A2" generation arrow, which also removes a potential second path to a generated (inout this, move that) via both M2 and A2 where M2 was already preferred - this removes the need for a tie-break and embraces the already-preferred path
The previous rule did not allow for expressing copy/move-constructible types that are not assignable (rare, but can happen when there are const members or Cpp1 reference members) - that can now be expressed by writing two operator='s, (out this, that) and (out this, move that)
-**(M)ove, M1, M2:** If you write a copy constructor or assignment operator, but not a corresponding move constructor or assignment operator, the latter is generated.
156
156
157
-
-**(A)ssignment, A1, A2, A3:** If you write a copy or move or converting constructor, but not a corresponding copy or move or converting assignment operator, the latter is generated.
157
+
-**(A)ssignment, A1, A3:** If you write a generalized constructor, but none of the three more-specific copy/move constructor/assignment functions, the latter three get generated. If you write a converting copy constructor, but no converting assignment operator for the same type, the latter is generated.
158
158
159
159
-**The arrows are transitive.** For example, if you write a copy constructor and nothing else, the move constructor, copy assignment operator, and move assignment operator are generated.
160
160
161
-
-**M2 is preferred over A2.** Both M2 and A2 can generate a missing `#!cpp (inout this, move that)` function. If both options are available, Cpp2 prefers to use M2 (generate move assignment from copy assignment, which could itself have been generated from copy construction) rather than A2 (generate move assignment from move construction). This is because M2 is a better fit: Move assignment is more like copy assignment than like move construction, because assignments are designed structurally to set the value of an existing `#!cpp this` object.
162
-
163
161
The most general `#!cpp operator=` with `that` is `#!cpp (out this, that)`. In Cpp1 terms, it generates all four combinations of { copy, move } x { constructor, assignment }. This is often sufficient, so you can write all these value-setting functions just once. If you do want to write a more specific version that does something else, though, you can always write it too.
164
162
165
163
> Note: Generating `#!cpp inout this` (assignment) from `#!cpp out this` also generates **converting assignment** from converting construction, which is a new thing. Today in Cpp1, if you write a converting constructor from another type `X`, you may or may not write the corresponding assignment from `X`; in Cpp2 you will get that by default, and it sets the object to the same state as the converting constructor from `X` does.
@@ -218,7 +216,7 @@ mytype: type
218
216
print();
219
217
}
220
218
221
-
print: (this) = std::cout << "value is [(name)$] [(social_handle)$]\n";
../../../include/cpp2util.h:2924:19: note: in instantiation of variable template specialization 'cpp2::impl::is_narrowing_v' requested here
83
+
../../../include/cpp2util.h:2929:19: note: in instantiation of variable template specialization 'cpp2::impl::is_narrowing_v' requested here
84
84
if constexpr (is_narrowing_v<C, CPP2_TYPEOF(x)>) {
85
85
^
86
86
pure2-expected-is-as.cpp2:39:28: note: in instantiation of function template specialization 'cpp2::impl::as_<int, double (&)(double) noexcept>' requested here
87
87
auto val1 {cpp2::impl::as_<int>(ex1)};
88
88
^
89
89
In file included from pure2-expected-is-as.cpp:7:
90
-
../../../include/cpp2util.h:2944:12: error: no matching function for call to 'as'
90
+
../../../include/cpp2util.h:2949:12: error: no matching function for call to 'as'
91
91
return as<C>(CPP2_FORWARD(x));
92
92
^~~~~
93
93
pure2-expected-is-as.cpp2:39:28: note: in instantiation of function template specialization 'cpp2::impl::as_<int, double (&)(double) noexcept>' requested here
94
94
auto val1 {cpp2::impl::as_<int>(ex1)};
95
95
^
96
-
../../../include/cpp2util.h:1902:16: note: candidate template ignored: constraints not satisfied [with C = int, x:auto = double (&)(double) noexcept]
96
+
../../../include/cpp2util.h:1907:16: note: candidate template ignored: constraints not satisfied [with C = int, x:auto = double (&)(double) noexcept]
97
97
constexpr auto as(auto&& x CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT_AS) -> decltype(auto)
98
98
^
99
-
../../../include/cpp2util.h:1908:18: note: because 'std::is_scalar_v<std::remove_cvref_t<decltype(x)> >' evaluated to false
99
+
../../../include/cpp2util.h:1913:18: note: because 'std::is_scalar_v<std::remove_cvref_t<decltype(x)> >' evaluated to false
../../../include/cpp2util.h:1909:17: note: and 'std::is_floating_point_v<std::remove_cvref_t<decltype(x)> >' evaluated to false
102
+
../../../include/cpp2util.h:1914:17: note: and 'std::is_floating_point_v<std::remove_cvref_t<decltype(x)> >' evaluated to false
103
103
|| std::is_floating_point_v<CPP2_TYPEOF(x)>
104
104
^
105
-
../../../include/cpp2util.h:1910:17: note: and 'std::is_base_of_v<int, std::remove_cvref_t<decltype(x)> >' evaluated to false
105
+
../../../include/cpp2util.h:1915:17: note: and 'std::is_base_of_v<int, std::remove_cvref_t<decltype(x)> >' evaluated to false
106
106
|| std::is_base_of_v<C, CPP2_TYPEOF(x)>
107
107
^
108
-
../../../include/cpp2util.h:1911:17: note: and 'std::is_base_of_v<std::remove_cvref_t<decltype(x)>, int>' evaluated to false
108
+
../../../include/cpp2util.h:1916:17: note: and 'std::is_base_of_v<std::remove_cvref_t<decltype(x)>, int>' evaluated to false
109
109
|| std::is_base_of_v<CPP2_TYPEOF(x), C>
110
110
^
111
-
../../../include/cpp2util.h:1912:30: note: and 'C({std::forward<decltype(x)>(x)})' would be invalid: cannot initialize a value of type 'int' with an lvalue of type 'double (double) noexcept'
111
+
../../../include/cpp2util.h:1917:30: note: and 'C({std::forward<decltype(x)>(x)})' would be invalid: cannot initialize a value of type 'int' with an lvalue of type 'double (double) noexcept'
112
112
|| requires { C{CPP2_FORWARD(x)}; }
113
113
^
114
-
../../../include/cpp2util.h:327:37: note: expanded from macro 'CPP2_FORWARD'
114
+
../../../include/cpp2util.h:333:37: note: expanded from macro 'CPP2_FORWARD'
../../../include/cpp2util.h:2041:6: note: candidate template ignored: constraints not satisfied [with C = int, X = double (&)(double) noexcept]
117
+
../../../include/cpp2util.h:2046:6: note: candidate template ignored: constraints not satisfied [with C = int, X = double (&)(double) noexcept]
118
118
auto as(X&& x CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT_AS) -> decltype(auto)
119
119
^
120
-
../../../include/cpp2util.h:2040:23: note: because 'specialization_of_template<double (&)(double) noexcept, std::variant>' evaluated to false
120
+
../../../include/cpp2util.h:2045:23: note: because 'specialization_of_template<double (&)(double) noexcept, std::variant>' evaluated to false
121
121
template< typename C, specialization_of_template<std::variant> X >
122
122
^
123
-
../../../include/cpp2util.h:892:7: note: because 'specialization_of_template_helper<C>(std::forward<X>(x))' would be invalid: no matching function for call to 'specialization_of_template_helper'
123
+
../../../include/cpp2util.h:897:7: note: because 'specialization_of_template_helper<C>(std::forward<X>(x))' would be invalid: no matching function for call to 'specialization_of_template_helper'
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/concepts:63:19: note: because '__detail::__same_as<double (double) noexcept, std::any>' evaluated to false
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/concepts:57:27: note: because 'std::is_same_v<double (double) noexcept, std::any>' evaluated to false
139
139
concept __same_as = std::is_same_v<_Tp, _Up>;
140
140
^
141
-
../../../include/cpp2util.h:2131:16: note: candidate template ignored: constraints not satisfied [with T = int, X = double (&)(double) noexcept]
141
+
../../../include/cpp2util.h:2136:16: note: candidate template ignored: constraints not satisfied [with T = int, X = double (&)(double) noexcept]
142
142
constexpr auto as( X&& x ) -> decltype(auto) {
143
143
^
144
-
../../../include/cpp2util.h:2130:22: note: because 'specialization_of_template<double (&)(double) noexcept, std::optional>' evaluated to false
144
+
../../../include/cpp2util.h:2135:22: note: because 'specialization_of_template<double (&)(double) noexcept, std::optional>' evaluated to false
../../../include/cpp2util.h:892:7: note: because 'specialization_of_template_helper<C>(std::forward<X>(x))' would be invalid: no matching function for call to 'specialization_of_template_helper'
147
+
../../../include/cpp2util.h:897:7: note: because 'specialization_of_template_helper<C>(std::forward<X>(x))' would be invalid: no matching function for call to 'specialization_of_template_helper'
Copy file name to clipboardExpand all lines: regression-tests/test-results/clang-12-c++20/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp.execution
-1Lines changed: 0 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,5 +4,4 @@ ctor - from string construct [ Henry | 123 Ford Dr. ]
4
4
ctor - from string assign [ Clara | 123 Ford Dr. ]
5
5
ctor - copy (GENERAL) cp-construct [ Clara | 123 Ford Dr. ] <- [ Clara | 123 Ford Dr. ]
6
6
ctor - move mv-construct [ Clara(CM) | 123 Ford Dr. ] <- [ | ]
7
-
ctor - copy (GENERAL) cp-assign [ Clara | 123 Ford Dr. ] <- [ Clara | 123 Ford Dr. ]
8
7
assign - move mv-assign [ Clara | 123 Ford Dr. ] <- [ | ]
Copy file name to clipboardExpand all lines: regression-tests/test-results/gcc-10-c++20/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp.execution
-1Lines changed: 0 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,5 +4,4 @@ ctor - from string construct [ Henry | 123 Ford Dr. ]
4
4
ctor - from string assign [ Clara | 123 Ford Dr. ]
5
5
ctor - copy (GENERAL) cp-construct [ Clara | 123 Ford Dr. ] <- [ Clara | 123 Ford Dr. ]
6
6
ctor - move mv-construct [ Clara(CM) | 123 Ford Dr. ] <- [ | ]
7
-
ctor - copy (GENERAL) cp-assign [ Clara | 123 Ford Dr. ] <- [ Clara | 123 Ford Dr. ]
8
7
assign - move mv-assign [ Clara | 123 Ford Dr. ] <- [ | ]
Copy file name to clipboardExpand all lines: regression-tests/test-results/gcc-14-c++2b/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp.execution
-1Lines changed: 0 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,5 +4,4 @@ ctor - from string construct [ Henry | 123 Ford Dr. ]
4
4
ctor - from string assign [ Clara | 123 Ford Dr. ]
5
5
ctor - copy (GENERAL) cp-construct [ Clara | 123 Ford Dr. ] <- [ Clara | 123 Ford Dr. ]
6
6
ctor - move mv-construct [ Clara(CM) | 123 Ford Dr. ] <- [ | ]
7
-
ctor - copy (GENERAL) cp-assign [ Clara | 123 Ford Dr. ] <- [ Clara | 123 Ford Dr. ]
8
7
assign - move mv-assign [ Clara | 123 Ford Dr. ] <- [ | ]
Copy file name to clipboardExpand all lines: regression-tests/test-results/msvc-2022-c++latest/pure2-types-smf-and-that-3-provide-mvconstruct-and-mvassign.cpp.execution
-1Lines changed: 0 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,5 +4,4 @@ ctor - from string construct [ Henry | 123 Ford Dr. ]
4
4
ctor - from string assign [ Clara | 123 Ford Dr. ]
5
5
ctor - copy (GENERAL) cp-construct [ Clara | 123 Ford Dr. ] <- [ Clara | 123 Ford Dr. ]
6
6
ctor - move mv-construct [ Clara(CM) | 123 Ford Dr. ] <- [ | ]
7
-
ctor - copy (GENERAL) cp-assign [ Clara | 123 Ford Dr. ] <- [ Clara | 123 Ford Dr. ]
8
7
assign - move mv-assign [ Clara | 123 Ford Dr. ] <- [ | ]
0 commit comments