Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/alloc-03-overload-new-1.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 /* check codegen for overloaded simple operator new/delete.
5 here check that we prefer the overload that accounts the function
6 args. */
7
8 #define PROVIDE_NEW_SZT
9 #define PROVIDE_NEW_SZT_INT
10 #define PROVIDE_DEL_VP
11
12 #include "../coro1-allocators.h"
13
14 int used_ovl_new = 0;
15 int used_ovl_del = 0;
16
17 struct coro1
18 f (int v) noexcept
19 {
20 PRINT ("coro1: about to return");
21 co_return;
22 }
23
24 int main ()
25 {
26 // Nest a scope so that we can inspect the flags after the DTORs run.
27 {
28 PRINT ("main: create coro1");
29 struct coro1 x = f (5);
30
31 if (used_ovl_new != 5)
32 {
33 PRINT ("main: apparently used the wrong op new...");
34 abort ();
35 }
36
37 PRINT ("main: got coro1 - resuming");
38 if (x.handle.done())
39 abort();
40 x.handle.resume();
41 PRINT ("main: after resume");
42 if (!x.handle.done())
43 {
44 PRINT ("main: apparently not done...");
45 abort ();
46 }
47 }
48
49 if (used_ovl_del != 1)
50 {
51 PRINT ("main: failed to call overloaded operator delete");
52 abort ();
53 }
54 PRINT ("main: returning");
55 return 0;
56 }