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 | 771c4a1775a66eee428398ce6fc3a911f962b088 (patch) | |
tree | ccc8f2a43b191d0e91b9e22fe47a0be9ba7a4744 /clang/test/SemaCXX/constexpr-value-init.cpp | |
parent | 1fc8263b4dae77b878a161ebe22e28f5ccfcfe4c (diff) | |
download | bcm5719-llvm-771c4a1775a66eee428398ce6fc3a911f962b088.tar.gz bcm5719-llvm-771c4a1775a66eee428398ce6fc3a911f962b088.zip |
constexpr: perform zero-initialization prior to / instead of performing a
constructor call when appropriate. Thanks to Eli for spotting this.
llvm-svn: 147271
Diffstat (limited to 'clang/test/SemaCXX/constexpr-value-init.cpp')
-rw-r--r-- | clang/test/SemaCXX/constexpr-value-init.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/constexpr-value-init.cpp b/clang/test/SemaCXX/constexpr-value-init.cpp new file mode 100644 index 00000000000..efa9e94da12 --- /dev/null +++ b/clang/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, ""); |