summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/constexpr-value-init.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-12-30 21:15:51 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-12-30 21:15:51 +0000
commitfddd384b7368b7b22719d5ab848837488810ccbe (patch)
tree175b1b078a16f92cec4c1907dd1025085f2de8eb /clang/test/SemaCXX/constexpr-value-init.cpp
parentcd1d447d62fcf8e806585f9e27215eaeeaa097d5 (diff)
downloadbcm5719-llvm-fddd384b7368b7b22719d5ab848837488810ccbe.tar.gz
bcm5719-llvm-fddd384b7368b7b22719d5ab848837488810ccbe.zip
Unrevert r147271, reverted in r147361.
Also temporarily remove the assumption from IR gen that we can emit IR for every constant we can fold, since it isn't currently true in C++11, to fix PR11676. Original comment from r147271: constexpr: perform zero-initialization prior to / instead of performing a constructor call when appropriate. Thanks to Eli for spotting this. llvm-svn: 147384
Diffstat (limited to 'clang/test/SemaCXX/constexpr-value-init.cpp')
-rw-r--r--clang/test/SemaCXX/constexpr-value-init.cpp31
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, "");
OpenPOWER on IntegriCloud