Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/pr101765.C

raw
1 // We cannot compile this yet, much run it - but one day it might be
2 // feasible, so do the minimum for now.
3 // { dg-additional-options " -fsyntax-only -Wno-vla" }
4 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
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 foo (int arg) noexcept
13 {
14 PRINTF ("foo arg = %d\n", arg);
15 char arr[arg]; /* { dg-message "sorry, unimplemented: variable length arrays are not yet supported in coroutines" "" { target *-*-* } } */
16 if (arg < 4)
17 co_return -6174;
18 else
19 for (int i = 0; i < arg; ++i) arr[i] = (char) i;
20 co_yield (int) arr[2];
21 co_return (int) arr[3];
22 }
23
24 int main ()
25 {
26 PRINT ("main: create coro1");
27 struct coro1 x = foo (10);
28 PRINT ("main: got coro1 - resuming");
29 if (x.handle.done())
30 abort();
31 x.handle.resume();
32 PRINT ("main: after resume");
33 int y = x.handle.promise().get_value();
34 if ( y == -6174 )
35 {
36 PRINT ("main: saw -6174");
37 return 1;
38 }
39 else if ( y != 2 )
40 abort;
41 x.handle.resume();
42 y = x.handle.promise().get_value();
43 if ( y != 3 )
44 abort ();
45 return 0;
46 }