diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-25 20:00:17 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-25 20:00:17 +0000 |
commit | eba05b2e396e1474f7bd6e8e8e1bd7752effef4d (patch) | |
tree | 84bb8feaaebede1ff2c5a9ff768c43df2c495927 /test/SemaCXX/constexpr-value-init.cpp | |
parent | 19b4a714de8841aed2727031674597f7efb62ce2 (diff) |
constexpr: perform zero-initialization prior to / instead of performing a
constructor call when appropriate. Thanks to Eli for spotting this.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147271 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/constexpr-value-init.cpp')
-rw-r--r-- | test/SemaCXX/constexpr-value-init.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/SemaCXX/constexpr-value-init.cpp b/test/SemaCXX/constexpr-value-init.cpp new file mode 100644 index 0000000000..efa9e94da1 --- /dev/null +++ b/test/SemaCXX/constexpr-value-init.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify + +struct A { + constexpr A() : a(b + 1), b(a + 1) {} // expected-note {{uninitialized}} + int a; + int b; +}; +struct B { + A a; +}; + +constexpr A a; // ok, zero initialization preceeds static initialization +void f() { + constexpr A a; // expected-error {{constant expression}} expected-note {{in call to 'A()'}} +} + +constexpr B b1; // expected-error {{requires a user-provided default constructor}} +constexpr B b2 = B(); // ok +static_assert(b2.a.a == 1, ""); +static_assert(b2.a.b == 2, ""); + +struct C { + int c; +}; +struct D : C { int d; }; +constexpr C c1; // expected-error {{requires a user-provided default constructor}} +constexpr C c2 = C(); // ok +constexpr D d1; // expected-error {{requires a user-provided default constructor}} +constexpr D d2 = D(); // expected-error {{constant expression}} expected-note {{non-literal type 'const D'}} +static_assert(D().c == 0, ""); +static_assert(D().d == 0, ""); |