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 f3()16constexpr int f3 () { A const &r { A() }; return r.i; } 17 SA(f3() == 0); f4()18constexpr int f4 () { A const &r { i: A() }; return r.i; } 19 SA(f4() == 42); f5()20constexpr int f5 () { A ar[1]{{ A() }}; return ar[0].i; } 21 SA(f5() == 0); f5a()22constexpr int f5a () { A ar[1]{{ i: A() }}; return ar[0].i; } 23 SA(f5a() == 42); 24 #if __cpp_constexpr >= 201907L f6()25constexpr int f6 () { A* p = new A{A()}; int i = p->i; delete p; return i; } 26 SA(f6() == 0); f6a()27constexpr int f6a () { A* p = new A{i:A()}; int i = p->i; delete p; return i; } 28 SA(f6a() == 42); 29 #endif 30 #endif f7(A a)31constexpr int f7 (A a) { return a.i; } 32 SA(f7({A()}) == 0); 33 SA(f7({i:A()}) == 42); 34