Skip to content

Commit 3e5a83a

Browse files
committed
Add basic _requires-clause_ support
Should merge user-written _requires-clause_ expressions with any generated from `forward` parameters
1 parent e606505 commit 3e5a83a

19 files changed

+143
-41
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
X: <T: type, U: type>
3+
type
4+
requires std::is_same_v<T, int>
5+
&& std::is_same_v<U, int>
6+
= {
7+
operator=: (out this) = { }
8+
}
9+
10+
f: <T: type, U: type>
11+
(forward a: int, forward b: int) -> int
12+
requires std::is_same_v<T, int>
13+
&& std::is_same_v<U, int>
14+
= {
15+
return a * b;
16+
}
17+
18+
main: () = {
19+
x: X<int,int> = ();
20+
std::cout << f<int,int>(2,5);
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10

regression-tests/test-results/clang-12/pure2-requires-clauses.cpp.output

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
abc

regression-tests/test-results/gcc-10/pure2-function-multiple-forward-arguments.cpp.output

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10

regression-tests/test-results/gcc-10/pure2-requires-clauses.cpp.output

Whitespace-only changes.

regression-tests/test-results/mixed-forwarding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ auto use(auto const& x) -> void{}
3636

3737
// invoking each of these with an rvalue std::pair argument ...
3838
auto apply_implicit_forward(auto&& t) -> void
39-
requires std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>
39+
requires (std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>)
4040
#line 16 "mixed-forwarding.cpp2"
4141
{
4242
copy_from(t.first); // copies
4343
copy_from(CPP2_FORWARD(t).second);// moves
4444
}
4545
auto apply_explicit_forward(auto&& t) -> void
46-
requires std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>
46+
requires (std::is_same_v<CPP2_TYPEOF(t), std::pair<X,X>>)
4747
#line 20 "mixed-forwarding.cpp2"
4848
{
4949
copy_from( CPP2_FORWARD(t).first);// moves

regression-tests/test-results/mixed-parameter-passing-with-forward.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ auto parameter_styles(
3434
std::string&& d,
3535
auto&& e
3636
) -> void
37-
requires std::is_same_v<CPP2_TYPEOF(e), std::string>
37+
requires (std::is_same_v<CPP2_TYPEOF(e), std::string>)
3838
#line 15 "mixed-parameter-passing-with-forward.cpp2"
3939
{
4040
int z {12};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
abc

0 commit comments

Comments
 (0)