Debian Codegraph @

gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C

raw
1 // PR c++/48089
2 // { dg-do compile { target c++11 } }
3
4 // bang is ill-formed (diagnostic required) because its initializer is
5 // non-constant, because it uses the value of an uninitialized object.
6
7 // s() is ill-formed (no diagnostic required) because there is no set of
8 // arguments that would produce a constant expression.
9
10 // R() is well-formed because i is initialized before j.
11
12 struct s {
13 constexpr s() : v(v) { } // { dg-error "accessing uninitialized member" }
14 int v;
15 };
16
17 constexpr s bang; // { dg-message "in .constexpr. expansion" }
18
19 struct R {
20 int i,j;
21 constexpr R() : i(42),j(i) { } // { dg-bogus "" }
22 };
23
24 constexpr R r; // { dg-bogus "" }
25
26 // Ill-formed (no diagnostic required)
27 struct T {
28 int i;
29 constexpr int f() { return i; } // { dg-error "accessing uninitialized member" }
30 constexpr T(): i(0) { }
31 constexpr T(const T& t) : i(f()) { } // { dg-message "in .constexpr. expansion" }
32 };
33
34 constexpr T t1;
35 // Ill-formed (diagnostic required)
36 constexpr T t2(t1); // { dg-message "in .constexpr. expansion" }
37
38 // Well-formed
39 struct U {
40 int i, j;
41 constexpr int f(int _i) { return _i; }
42 constexpr int g() { return i; }
43 constexpr U(): i(0), j(0) { }
44 constexpr U(const U& t) : i(f(t.i)),j(0) { } // { dg-bogus "" }
45 constexpr U(int _i) : i(_i),j(g()) { } // { dg-bogus "" }
46 };
47
48 constexpr U u1;
49 constexpr U u2(u1); // { dg-bogus "" }
50 constexpr U u3(1); // { dg-bogus "" }