OSDN Git Service

2012-12-15 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / cpp0x / constexpr-48089.C
1 // PR c++/48089
2 // { dg-options -std=c++0x }
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-message "" }
14   int v;
15 };
16
17 constexpr s bang;               // { dg-message "" }
18
19 struct R {
20   int i,j;
21   constexpr R() : i(42),j(i) { } // { dg-bogus "" "" { xfail *-*-* } }
22 };
23
24 constexpr R r;                  // { dg-bogus "" "" { xfail *-*-* } }
25
26 // Ill-formed (no diagnostic required)
27 struct T {
28   int i;
29   constexpr int f() { return i; }
30   constexpr T(): i(0) { }
31   constexpr T(const T& t) : i(f()) { } // { dg-message "" }
32 };
33
34 constexpr T t1;
35 // Ill-formed (diagnostic required)
36 constexpr T t2(t1);             // { dg-message "" }
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 "" "" { xfail *-*-* } }
45   constexpr U(int _i) : i(_i),j(g()) { } // { dg-bogus "" "" { xfail *-*-* } }
46 };
47
48 constexpr U u1;
49 constexpr U u2(u1);             // { dg-bogus "" "" { xfail *-*-* } }
50 constexpr U u3(1);              // { dg-bogus "" "" { xfail *-*-* } }