diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-30 21:15:51 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-30 21:15:51 +0000 |
commit | 51201882382fb40c9456a06c7f93d6ddd4a57712 (patch) | |
tree | 2b485b2651f5385cda9709b77582bf4320e3569f /test | |
parent | bf3cc73db94f2fbeb57929887bd05d5a0e077f0c (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147384 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/CXX/expr/expr.const/p2-0x.cpp | 4 | ||||
-rw-r--r-- | test/CXX/special/class.ctor/p6-0x.cpp | 12 | ||||
-rw-r--r-- | test/CodeGenCXX/value-init.cpp | 3 | ||||
-rw-r--r-- | test/SemaCXX/constexpr-printing.cpp | 7 | ||||
-rw-r--r-- | test/SemaCXX/constexpr-value-init.cpp | 31 | ||||
-rw-r--r-- | test/SemaObjCXX/arc-type-traits.mm | 16 |
6 files changed, 57 insertions, 16 deletions
diff --git a/test/CXX/expr/expr.const/p2-0x.cpp b/test/CXX/expr/expr.const/p2-0x.cpp index d95af8a95f..f0581fcc09 100644 --- a/test/CXX/expr/expr.const/p2-0x.cpp +++ b/test/CXX/expr/expr.const/p2-0x.cpp @@ -33,11 +33,11 @@ struct NonConstexpr3 { int m : NonConstexpr2().n; // expected-error {{constant expression}} expected-note {{undefined constructor 'NonConstexpr2'}} }; struct NonConstexpr4 { - NonConstexpr4(); + NonConstexpr4(); // expected-note {{declared here}} int n; }; struct NonConstexpr5 { - int n : NonConstexpr4().n; // expected-error {{constant expression}} expected-note {{non-literal type 'NonConstexpr4' cannot be used in a constant expression}} + int n : NonConstexpr4().n; // expected-error {{constant expression}} expected-note {{non-constexpr constructor 'NonConstexpr4' cannot be used in a constant expression}} }; // - an invocation of an undefined constexpr function or an undefined diff --git a/test/CXX/special/class.ctor/p6-0x.cpp b/test/CXX/special/class.ctor/p6-0x.cpp index 19e324d8df..71afd244bd 100644 --- a/test/CXX/special/class.ctor/p6-0x.cpp +++ b/test/CXX/special/class.ctor/p6-0x.cpp @@ -8,8 +8,16 @@ struct NonConstexpr1 { // expected-note {{here}} struct NonConstexpr2 { // expected-note {{here}} NonConstexpr1 nl; }; -constexpr NonConstexpr1 nc1 = NonConstexpr1(); // expected-error {{constant expression}} expected-note {{non-constexpr constructor 'NonConstexpr1'}} -constexpr NonConstexpr2 nc2 = NonConstexpr2(); // expected-error {{constant expression}} expected-note {{non-constexpr constructor 'NonConstexpr2'}} +struct NonConstexpr2a : NonConstexpr1 { }; +constexpr NonConstexpr1 nc1 = NonConstexpr1(); // ok, does not call constructor +constexpr NonConstexpr2 nc2 = NonConstexpr2(); // ok, does not call constructor +constexpr NonConstexpr2a nc2a = NonConstexpr2a(); // expected-error {{constant expression}} expected-note {{non-literal type 'const NonConstexpr2a'}} +constexpr int nc2_a = NonConstexpr2().nl.a; // ok +constexpr int nc2a_a = NonConstexpr2a().a; // ok +struct Helper { + friend constexpr NonConstexpr1::NonConstexpr1(); // expected-error {{follows non-constexpr declaration}} + friend constexpr NonConstexpr2::NonConstexpr2(); // expected-error {{follows non-constexpr declaration}} +}; struct Constexpr1 {}; constexpr Constexpr1 c1 = Constexpr1(); // ok diff --git a/test/CodeGenCXX/value-init.cpp b/test/CodeGenCXX/value-init.cpp index fb981d1ff7..6e60f80110 100644 --- a/test/CodeGenCXX/value-init.cpp +++ b/test/CodeGenCXX/value-init.cpp @@ -134,8 +134,7 @@ namespace zeroinit { // CHECK: define i32 @_ZN8zeroinit4testEv() int test() { // CHECK: call void @llvm.memset.p0i8.i64 - // CHECK: getelementptr - // CHECK: ret i32 + // CHECK: ret i32 0 return S().i; } diff --git a/test/SemaCXX/constexpr-printing.cpp b/test/SemaCXX/constexpr-printing.cpp index e6cf209819..cccefca9fa 100644 --- a/test/SemaCXX/constexpr-printing.cpp +++ b/test/SemaCXX/constexpr-printing.cpp @@ -11,8 +11,11 @@ struct S { constexpr int extract(const S &s) { return s.n; } // expected-note {{read of uninitialized object is not allowed in a constant expression}} -constexpr S s1; // expected-error {{constant expression}} expected-note {{in call to 'S()'}} -constexpr S s2(10); +constexpr S s1; // ok +void f() { + constexpr S s1; // expected-error {{constant expression}} expected-note {{in call to 'S()'}} + constexpr S s2(10); +} typedef __attribute__((vector_size(16))) int vector_int; 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, ""); diff --git a/test/SemaObjCXX/arc-type-traits.mm b/test/SemaObjCXX/arc-type-traits.mm index b876018e25..9877870f94 100644 --- a/test/SemaObjCXX/arc-type-traits.mm +++ b/test/SemaObjCXX/arc-type-traits.mm @@ -53,16 +53,16 @@ TRAIT_IS_TRUE(__has_trivial_destructor, __autoreleasing id); TRAIT_IS_TRUE(__has_trivial_destructor, __unsafe_unretained id); // __is_literal -TRAIT_IS_FALSE(__is_literal, __strong id); -TRAIT_IS_FALSE(__is_literal, __weak id); -TRAIT_IS_FALSE(__is_literal, __autoreleasing id); -TRAIT_IS_FALSE(__is_literal, __unsafe_unretained id); +TRAIT_IS_TRUE(__is_literal, __strong id); +TRAIT_IS_TRUE(__is_literal, __weak id); +TRAIT_IS_TRUE(__is_literal, __autoreleasing id); +TRAIT_IS_TRUE(__is_literal, __unsafe_unretained id); // __is_literal_type -TRAIT_IS_FALSE(__is_literal_type, __strong id); -TRAIT_IS_FALSE(__is_literal_type, __weak id); -TRAIT_IS_FALSE(__is_literal_type, __autoreleasing id); -TRAIT_IS_FALSE(__is_literal_type, __unsafe_unretained id); +TRAIT_IS_TRUE(__is_literal_type, __strong id); +TRAIT_IS_TRUE(__is_literal_type, __weak id); +TRAIT_IS_TRUE(__is_literal_type, __autoreleasing id); +TRAIT_IS_TRUE(__is_literal_type, __unsafe_unretained id); // __is_pod TRAIT_IS_FALSE(__is_pod, __strong id); |