Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/desig19.C

raw
1 // { dg-do compile { target c++11 } }
2 // { dg-options "" }
3
4 struct A
5 {
6 int i;
7 constexpr operator int() { return 42; }
8 };
9
10 #define SA(X) static_assert ((X),#X)
11 constexpr A a1 { A() };
12 SA(a1.i == 0);
13 constexpr A a2 { i: A() };
14 SA(a2.i == 42);
15 #if __cpp_constexpr >= 201304L
16 constexpr int f3 () { A const &r { A() }; return r.i; }
17 SA(f3() == 0);
18 constexpr int f4 () { A const &r { i: A() }; return r.i; }
19 SA(f4() == 42);
20 constexpr int f5 () { A ar[1]{{ A() }}; return ar[0].i; }
21 SA(f5() == 0);
22 constexpr int f5a () { A ar[1]{{ i: A() }}; return ar[0].i; }
23 SA(f5a() == 42);
24 #if __cpp_constexpr >= 201907L
25 constexpr int f6 () { A* p = new A{A()}; int i = p->i; delete p; return i; }
26 SA(f6() == 0);
27 constexpr int f6a () { A* p = new A{i:A()}; int i = p->i; delete p; return i; }
28 SA(f6a() == 42);
29 #endif
30 #endif
31 constexpr int f7 (A a) { return a.i; }
32 SA(f7({A()}) == 0);
33 SA(f7({i:A()}) == 42);