Richard Smith | 5120188 | 2011-12-30 21:15:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify |
| 2 | |
| 3 | struct A { |
Richard Smith | bebf5b1 | 2013-04-26 14:36:30 +0000 | [diff] [blame] | 4 | constexpr A() : a(b + 1), b(a + 1) {} // expected-note {{outside its lifetime}} |
Richard Smith | 5120188 | 2011-12-30 21:15:51 +0000 | [diff] [blame] | 5 | int a; |
| 6 | int b; |
| 7 | }; |
| 8 | struct B { |
| 9 | A a; |
| 10 | }; |
| 11 | |
| 12 | constexpr A a; // ok, zero initialization preceeds static initialization |
| 13 | void f() { |
| 14 | constexpr A a; // expected-error {{constant expression}} expected-note {{in call to 'A()'}} |
| 15 | } |
| 16 | |
| 17 | constexpr B b1; // expected-error {{requires a user-provided default constructor}} |
| 18 | constexpr B b2 = B(); // ok |
| 19 | static_assert(b2.a.a == 1, ""); |
| 20 | static_assert(b2.a.b == 2, ""); |
| 21 | |
| 22 | struct C { |
| 23 | int c; |
| 24 | }; |
| 25 | struct D : C { int d; }; |
| 26 | constexpr C c1; // expected-error {{requires a user-provided default constructor}} |
| 27 | constexpr C c2 = C(); // ok |
| 28 | constexpr D d1; // expected-error {{requires a user-provided default constructor}} |
Richard Smith | 86c3ae4 | 2012-02-13 03:54:03 +0000 | [diff] [blame] | 29 | constexpr D d2 = D(); // ok with DR1452 |
Richard Smith | 5120188 | 2011-12-30 21:15:51 +0000 | [diff] [blame] | 30 | static_assert(D().c == 0, ""); |
| 31 | static_assert(D().d == 0, ""); |
Richard Smith | ce582fe | 2012-02-17 00:44:16 +0000 | [diff] [blame] | 32 | |
| 33 | struct V : virtual C {}; |
| 34 | template<typename T> struct Z : T { |
| 35 | constexpr Z() : V() {} |
| 36 | }; |
| 37 | constexpr int n = Z<V>().c; // expected-error {{constant expression}} expected-note {{virtual base class}} |