comparison gcc/testsuite/g++.dg/coroutines/torture/local-var-4.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 // { dg-do run }
2
3 // Test modifying a local var across nested scopes containing vars
4 // hiding those at outer scopes.
5
6 #include "../coro.h"
7
8 // boiler-plate for tests of codegen
9 #include "../coro1-ret-int-yield-int.h"
10
11 struct coro1
12 f (int start) noexcept
13 {
14 int value = start;
15 {
16 int value = start + 5;
17 {
18 int value = start + 20;
19 }
20 {
21 int value = start + 1;
22 PRINT ("f: about to yield start");
23 co_yield value;
24 }
25 }
26
27 value -= 31;
28 PRINT ("f: about to yield (value-31)");
29 co_yield value;
30
31 value += 6163;
32 PRINT ("f: about to return (value+6163)");
33 co_return value;
34 }
35
36 int main ()
37 {
38 PRINT ("main: create coro1");
39 struct coro1 x = f (42);
40 PRINT ("main: got coro1 - resuming (1)");
41 if (x.handle.done())
42 abort();
43 x.handle.resume();
44 PRINT ("main: after resume (1)");
45 int y = x.handle.promise().get_value();
46 if ( y != 43 )
47 abort ();
48 PRINT ("main: apparently got 42 - resuming (2)");
49 if (x.handle.done())
50 abort();
51 x.handle.resume();
52 PRINT ("main: after resume (2)");
53 y = x.handle.promise().get_value();
54 if ( y != 11 )
55 abort ();
56 PRINT ("main: apparently got 11 - resuming (3)");
57 if (x.handle.done())
58 {
59 PRINT ("main: done?");
60 abort();
61 }
62 x.handle.resume();
63 PRINT ("main: after resume (2) checking return");
64 y = x.handle.promise().get_value();
65 if ( y != 6174 )
66 abort ();
67 PRINT ("main: apparently got 6174");
68 if (!x.handle.done())
69 {
70 PRINT ("main: apparently not done...");
71 abort ();
72 }
73 PRINT ("main: returning");
74 return 0;
75 }