Skip to content

Commit de3f54f

Browse files
committed
Fix cpp2::move
I don't recall why we had the more complex design of "move only from copyable types"... rvalues can be of any type, so the extra overload for noncopyable types isn't needed This change highlighted that a handful of tests in pure2-last-use.cpp2 were incorrect, fixing those too
1 parent 923beea commit de3f54f

File tree

7 files changed

+86
-101
lines changed

7 files changed

+86
-101
lines changed

include/cpp2util.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -672,17 +672,10 @@ concept valid_custom_is_operator = predicate_member_fun<X, F, &F::op_is>
672672
//
673673

674674
template <typename T>
675-
requires (std::is_copy_constructible_v<std::remove_cvref_t<T>>)
676675
inline constexpr auto move(T&& t) -> decltype(auto) {
677676
return std::move(t);
678677
}
679678

680-
template <typename T>
681-
requires (!std::is_copy_constructible_v<std::remove_cvref_t<T>>)
682-
inline constexpr auto move(T&& t) -> decltype(auto) {
683-
return std::forward<T>(t);
684-
}
685-
686679
inline constexpr auto max(auto... values) {
687680
return std::max( { values... } );
688681
}

regression-tests/pure2-last-use.cpp2

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ issue_847_0: (copy v: std::vector<std::unique_ptr<int>>) = {
136136
do (_) {
137137
}
138138
}
139-
issue_847_1: (move v: std::vector<std::unique_ptr<int>>) = {
140-
for v.make_copy()
141-
do (move x) {
142-
f_inout(x);
143-
}
144-
}
139+
// issue_847_1: (move v: std::vector<std::unique_ptr<int>>) = {
140+
// for v.make_copy()
141+
// do (move x) {
142+
// f_inout(x); // error, can't pass rvalue to inout param
143+
// }
144+
// }
145145
issue_847_5: (forward v) = {
146146
for v.make_copy()
147147
do (forward x) {
@@ -170,10 +170,10 @@ issue_857: type = {
170170
a: std::unique_ptr<int>;
171171
b: std::unique_ptr<int>;
172172
operator=: (out this, move that) = { }
173-
operator=: (move this) = {
174-
f_inout(a);
175-
f_inout(this.b);
176-
}
173+
// operator=: (move this) = {
174+
// f_inout(a); // error, can't pass rvalue to inout param
175+
// f_inout(this.b); // error, can't pass rvalue to inout param
176+
// }
177177
//f: (move this) = f_copy(this);
178178
//f: (move this, move that) = f_copy(this, that);
179179
//g: (move this) = f_copy(this.a);
@@ -363,7 +363,7 @@ issue_857_9: @struct type = {
363363
//f3: (move this) = d();
364364

365365
// OK: Explicit 'this' for base members, like in templates.
366-
g0: (move this) = f_inout(this.a);
366+
//g0: (move this) = f_inout(this.a); // error, can't pass rvalue to inout param
367367
//g1: (move this) = _ = this.b();
368368
g2: (move this) = f_inout(this.c);
369369
//g3: (move this) = this.d();
@@ -806,6 +806,7 @@ enum_0: () = {
806806
enum_1: () = {
807807
max_value := new<int>(0);
808808
min_value: std::reference_wrapper<const std::unique_ptr<int>> = max_value;
809+
_ = max_value;
809810

810811
// for (0)
811812
// do (copy x)
@@ -947,7 +948,7 @@ g: () = {
947948
_ = :() = {
948949
x := new<int>(0);
949950
f_inout(x);
950-
// _ = :() -> int = (:() x$*)$();
951+
_ = :() -> int = (:() x$*)$();
951952
};
952953
}
953954

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pure2-last-use.cpp2:944:44: error: a lambda expression cannot appear in this context
1+
pure2-last-use.cpp2:945:44: error: a lambda expression cannot appear in this context
22
static_cast<void>([_0 = std::array<int,[](auto const& x) mutable -> auto { return identity(x); }(0)>()]() mutable -> auto { return _0; });// Fails on Clang 12 (lambda in unevaluated context).
33
^
44
1 error generated.
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
In file included from mixed-bugfix-for-ufcs-non-local.cpp:6:
22
../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type
3-
2100 | //
3+
2100 | //-------------------------------------------------------------------------------------------------------------
44
| ^
55
../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’
6-
2137 | // Value case
6+
2137 |
77
| ^
88
mixed-bugfix-for-ufcs-non-local.cpp2:13:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’
99
mixed-bugfix-for-ufcs-non-local.cpp2:13:36: error: template argument 1 is invalid
1010
../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type
11-
2100 | //
11+
2100 | //-------------------------------------------------------------------------------------------------------------
1212
| ^
1313
../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’
14-
2137 | // Value case
14+
2137 |
1515
| ^
1616
mixed-bugfix-for-ufcs-non-local.cpp2:21:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’
1717
mixed-bugfix-for-ufcs-non-local.cpp2:21:36: error: template argument 1 is invalid
1818
../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type
19-
2100 | //
19+
2100 | //-------------------------------------------------------------------------------------------------------------
2020
| ^
2121
../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’
22-
2137 | // Value case
22+
2137 |
2323
| ^
2424
mixed-bugfix-for-ufcs-non-local.cpp2:31:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’
2525
mixed-bugfix-for-ufcs-non-local.cpp2:31:36: error: template argument 1 is invalid
2626
../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type
27-
2100 | //
27+
2100 | //-------------------------------------------------------------------------------------------------------------
2828
| ^
2929
../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’
30-
2137 | // Value case
30+
2137 |
3131
| ^
3232
mixed-bugfix-for-ufcs-non-local.cpp2:33:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’
3333
mixed-bugfix-for-ufcs-non-local.cpp2:33:36: error: template argument 1 is invalid
3434
../../../include/cpp2util.h:2100:1: error: lambda-expression in template parameter type
35-
2100 | //
35+
2100 | //-------------------------------------------------------------------------------------------------------------
3636
| ^
3737
../../../include/cpp2util.h:2137:59: note: in expansion of macro ‘CPP2_UFCS_’
38-
2137 | // Value case
38+
2137 |
3939
| ^
4040
mixed-bugfix-for-ufcs-non-local.cpp2:21:12: note: in expansion of macro ‘CPP2_UFCS_NONLOCAL’
4141
mixed-bugfix-for-ufcs-non-local.cpp2:21:36: error: template argument 1 is invalid

0 commit comments

Comments
 (0)