Skip to content

Commit ab07950

Browse files
committed
test: add test case for perfect backwarding
1 parent 7b5310d commit ab07950

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

regression-tests/pure2-forward-return.cpp2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ first: (forward rng) -> forward _
66

77
global: const int = 42;
88
f: () -> forward const int = { return global; }
9+
f: (x: int) x;
10+
f: (x: long) _ = x;
11+
g: (x) -> decltype(auto) = f(x);
912

1013
main: () -> int = {
1114
v : std::vector = (1,2,3);
1215
first(v) = 4;
1316
std::cout << first(v) << std::endl; // prints: 4
1417
std::cout << f() << std::endl; // prints: 42
18+
std::cout << g(0) << std::endl; // prints: 0
19+
g(0L);
1520
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
4
22
42
3+
0

regression-tests/test-results/pure2-forward-return.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#line 7 "pure2-forward-return.cpp2"
2020
extern int const global;
2121
[[nodiscard]] auto f() -> int const&;
22+
[[nodiscard]] auto f(cpp2::in<int> x) -> auto;
23+
[[nodiscard]] auto f(cpp2::in<long> x) -> auto;
24+
[[nodiscard]] auto g(auto const& x) -> decltype(auto);
2225

2326
[[nodiscard]] auto main() -> int;
2427

@@ -35,11 +38,16 @@ extern int const global;
3538

3639
int const global {42};
3740
[[nodiscard]] auto f() -> int const&{return global; }
41+
[[nodiscard]] auto f(cpp2::in<int> x) -> auto { return x; }
42+
[[nodiscard]] auto f(cpp2::in<long> x) -> auto { return static_cast<void>(x); }
43+
[[nodiscard]] auto g(auto const& x) -> decltype(auto) { return f(x); }
3844

3945
[[nodiscard]] auto main() -> int{
4046
std::vector v {1, 2, 3};
4147
first(v) = 4;
4248
std::cout << first(std::move(v)) << std::endl;// prints: 4
4349
std::cout << f() << std::endl; // prints: 42
50+
std::cout << g(0) << std::endl; // prints: 0
51+
g(0L);
4452
}
4553

0 commit comments

Comments
 (0)