Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/coroutines/torture/func-params-07.C @ 152:2b5abeee2509
update gcc11
author | anatofuz |
---|---|
date | Mon, 25 May 2020 07:50:57 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
145:1830386684a0 | 152:2b5abeee2509 |
---|---|
1 // { dg-do run } | |
2 | |
3 // Test that we copy simple parms correctly by value, reference or | |
4 // rvalue reference. | |
5 | |
6 #include "../coro.h" | |
7 | |
8 // boiler-plate for tests of codegen | |
9 #include "../coro1-refs-and-ctors.h" | |
10 | |
11 coro1 | |
12 my_coro (int v1, int& v2, int&& v3) | |
13 { | |
14 co_yield v1 + v2 + v3; | |
15 co_return v1 + v2 + v3; | |
16 } | |
17 | |
18 int main () | |
19 { | |
20 PRINT ("main: create coro1"); | |
21 int lv = 1; | |
22 int lvr = 2; | |
23 coro1 x = my_coro (lv, lvr, lvr+2); | |
24 | |
25 if (x.handle.done()) | |
26 abort(); | |
27 | |
28 x.handle.resume(); | |
29 PRINT ("main: after resume (initial suspend)"); | |
30 | |
31 /* Now we should have the co_yielded value. */ | |
32 int y = x.handle.promise().get_value(); | |
33 if ( y != 7 ) | |
34 { | |
35 PRINTF ("main: wrong result (%d).", y); | |
36 abort (); | |
37 } | |
38 | |
39 /* So we should be suspended at the yield, now change the | |
40 values so that we can determine that the reference persists | |
41 and the copy was made correctly. */ | |
42 lv = 5; // should be ignored | |
43 lvr = 3; // should be enacted | |
44 | |
45 x.handle.resume(); | |
46 PRINT ("main: after resume (yield)"); | |
47 | |
48 /* Now we should have the co_returned value. */ | |
49 y = x.handle.promise().get_value(); | |
50 if ( y != 8 ) | |
51 { | |
52 PRINTF ("main: wrong result (%d).", y); | |
53 abort (); | |
54 } | |
55 | |
56 y = x.handle.promise().get_v2(); | |
57 if ( y != 2 ) | |
58 { | |
59 PRINTF ("main: wrong result 2 (%d).", y); | |
60 abort (); | |
61 } | |
62 | |
63 y = x.handle.promise().get_v3(); | |
64 if ( y != 4 ) | |
65 { | |
66 PRINTF ("main: wrong result 3 (%d).", y); | |
67 abort (); | |
68 } | |
69 | |
70 if (!x.handle.done()) | |
71 { | |
72 PRINT ("main: apparently not done..."); | |
73 abort (); | |
74 } | |
75 | |
76 x.handle.destroy(); | |
77 x.handle = NULL; | |
78 | |
79 PRINT ("main: returning"); | |
80 return 0; | |
81 } |