summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-07-07 08:35:56 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-07-07 08:35:56 +0000
commite20c83d9ede057602e78c482e644a3d44a966f36 (patch)
tree9c1259476ea5f128132f8c47606d079cf9fb6d37 /clang/test
parent4ff9ff974cc1944cc5f38c2c808938a29f235d60 (diff)
downloadbcm5719-llvm-e20c83d9ede057602e78c482e644a3d44a966f36.tar.gz
bcm5719-llvm-e20c83d9ede057602e78c482e644a3d44a966f36.zip
PR12670: Support for initializing an array of non-aggregate class type from an
initializer list. Patch by Olivier Goffart, with extra testcases by Meador Inge and Daniel Lunow. llvm-svn: 159896
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp113
-rw-r--r--clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp37
-rw-r--r--clang/test/SemaCXX/constant-expression-cxx11.cpp12
-rw-r--r--clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp29
-rw-r--r--clang/test/SemaCXX/dcl_init_aggr.cpp2
5 files changed, 192 insertions, 1 deletions
diff --git a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp
new file mode 100644
index 00000000000..3450003a6e2
--- /dev/null
+++ b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp
@@ -0,0 +1,113 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+namespace std {
+ typedef decltype(sizeof(int)) size_t;
+
+ template <typename E>
+ struct initializer_list
+ {
+ const E *p;
+ size_t n;
+ initializer_list(const E *p, size_t n) : p(p), n(n) {}
+ };
+
+ struct string {
+ string(const char *);
+ };
+
+ template<typename A, typename B>
+ struct pair {
+ pair(const A&, const B&);
+ };
+}
+
+namespace bullet2 {
+ double ad[] = { 1, 2.0 };
+ int ai[] = { 1, 2.0 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
+
+ struct S2 {
+ int m1;
+ double m2, m3;
+ };
+
+ S2 s21 = { 1, 2, 3.0 };
+ S2 s22 { 1.0, 2, 3 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
+ S2 s23 { };
+}
+
+namespace bullet4_example1 {
+ struct S {
+ S(std::initializer_list<double> d) {}
+ S(std::initializer_list<int> i) {}
+ S() {}
+ };
+
+ S s1 = { 1.0, 2.0, 3.0 };
+ S s2 = { 1, 2, 3 };
+ S s3 = { };
+}
+
+namespace bullet4_example2 {
+ struct Map {
+ Map(std::initializer_list<std::pair<std::string,int>>) {}
+ };
+
+ Map ship = {{"Sophie",14}, {"Surprise",28}};
+}
+
+namespace bullet4_example3 {
+ struct S {
+ S(int, double, double) {}
+ S() {}
+ };
+
+ S s1 = { 1, 2, 3.0 };
+ // FIXME: This is an ill-formed narrowing initialization.
+ S s2 { 1.0, 2, 3 };
+ S s3 {};
+}
+
+namespace bullet5 {
+ struct S {
+ S(std::initializer_list<double>) {}
+ S(const std::string &) {}
+ };
+
+ const S& r1 = { 1, 2, 3.0 };
+ const S& r2 = { "Spinach" };
+ S& r3 = { 1, 2, 3 }; // expected-error {{non-const lvalue reference to type 'bullet5::S' cannot bind to an initializer list temporary}}
+ const int& i1 = { 1 };
+ const int& i2 = { 1.1 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}} expected-warning {{implicit conversion}}
+ const int (&iar)[2] = { 1, 2 };
+}
+
+namespace bullet6 {
+ int x1 {2};
+ int x2 {2.0}; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
+}
+
+namespace bullet7 {
+ int** pp {};
+}
+
+namespace bullet8 {
+ struct A { int i; int j; };
+ A a1 { 1, 2 };
+ A a2 { 1.2 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}} expected-warning {{implicit conversion}}
+
+ struct B {
+ B(std::initializer_list<int> i) {}
+ };
+ B b1 { 1, 2 };
+ B b2 { 1, 2.0 };
+
+ struct C {
+ C(int i, double j) {}
+ };
+ C c1 = { 1, 2.2 };
+ // FIXME: This is an ill-formed narrowing initialization.
+ C c2 = { 1.1, 2 }; // expected-warning {{implicit conversion}}
+
+ int j { 1 };
+ int k { };
+}
diff --git a/clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp b/clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp
new file mode 100644
index 00000000000..e141f30ccac
--- /dev/null
+++ b/clang/test/CodeGenCXX/cxx0x-initializer-constructors.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c++11 -S -emit-llvm -o - %s | FileCheck %s
+
+struct S {
+ S(int x) { }
+ S(int x, double y, double z) { }
+};
+
+void fn1() {
+ // CHECK: define void @_Z3fn1v
+ S s { 1 };
+ // CHECK: alloca %struct.S, align 1
+ // CHECK: call void @_ZN1SC1Ei(%struct.S* %s, i32 1)
+}
+
+void fn2() {
+ // CHECK: define void @_Z3fn2v
+ S s { 1, 2.0, 3.0 };
+ // CHECK: alloca %struct.S, align 1
+ // CHECK: call void @_ZN1SC1Eidd(%struct.S* %s, i32 1, double 2.000000e+00, double 3.000000e+00)
+}
+
+void fn3() {
+ // CHECK: define void @_Z3fn3v
+ S sa[] { { 1 }, { 2 }, { 3 } };
+ // CHECK: alloca [3 x %struct.S], align 1
+ // CHECK: call void @_ZN1SC1Ei(%struct.S* %arrayinit.begin, i32 1)
+ // CHECK: call void @_ZN1SC1Ei(%struct.S* %arrayinit.element, i32 2)
+ // CHECK: call void @_ZN1SC1Ei(%struct.S* %arrayinit.element1, i32 3)
+}
+
+void fn4() {
+ // CHECK: define void @_Z3fn4v
+ S sa[] { { 1, 2.0, 3.0 }, { 4, 5.0, 6.0 } };
+ // CHECK: alloca [2 x %struct.S], align 1
+ // CHECK: call void @_ZN1SC1Eidd(%struct.S* %arrayinit.begin, i32 1, double 2.000000e+00, double 3.000000e+00)
+ // CHECK: call void @_ZN1SC1Eidd(%struct.S* %arrayinit.element, i32 4, double 5.000000e+00, double 6.000000e+00)
+}
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index facd4375b0c..2cd66b6f626 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1318,3 +1318,15 @@ namespace PR13273 {
// actually call it.
static_assert(S{}.t == 0, "");
}
+
+namespace PR12670 {
+ struct S {
+ constexpr S(int a0) : m(a0) {}
+ constexpr S() : m(6) {}
+ int m;
+ };
+ constexpr S x[3] = { {4}, 5 };
+ static_assert(x[0].m == 4, "");
+ static_assert(x[1].m == 5, "");
+ static_assert(x[2].m == 6, "");
+}
diff --git a/clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp b/clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp
index 801a82f5706..c83058a5e19 100644
--- a/clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp
+++ b/clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp
@@ -87,3 +87,32 @@ namespace array_explicit_conversion {
(void)test4{{{1}}}; // expected-note {{in instantiation of template class 'array_explicit_conversion::A<-1>' requested here}}
}
}
+
+namespace sub_constructor {
+ struct DefaultConstructor { // expected-note 2 {{not viable}}
+ DefaultConstructor(); // expected-note {{not viable}}
+ int x;
+ };
+ struct NoDefaultConstructor1 { // expected-note 2 {{not viable}}
+ NoDefaultConstructor1(int); // expected-note {{not viable}}
+ int x;
+ };
+ struct NoDefaultConstructor2 { // expected-note 4 {{not viable}}
+ NoDefaultConstructor2(int,int); // expected-note 2 {{not viable}}
+ int x;
+ };
+
+ struct Aggr {
+ DefaultConstructor a;
+ NoDefaultConstructor1 b;
+ NoDefaultConstructor2 c;
+ };
+
+ Aggr ok1 { {}, {0} , {0,0} };
+ Aggr ok2 = { {}, {0} , {0,0} };
+ Aggr too_many { {0} , {0} , {0,0} }; // expected-error {{no matching constructor for initialization}}
+ Aggr too_few { {} , {0} , {0} }; // expected-error {{no matching constructor for initialization}}
+ Aggr invalid { {} , {&ok1} , {0,0} }; // expected-error {{no matching constructor for initialization}}
+ NoDefaultConstructor2 array_ok[] = { {0,0} , {0,1} };
+ NoDefaultConstructor2 array_error[] = { {0,0} , {0} }; // expected-error {{no matching constructor for initialization}}
+} \ No newline at end of file
diff --git a/clang/test/SemaCXX/dcl_init_aggr.cpp b/clang/test/SemaCXX/dcl_init_aggr.cpp
index bd3de9eb7e1..8c5e654fca2 100644
--- a/clang/test/SemaCXX/dcl_init_aggr.cpp
+++ b/clang/test/SemaCXX/dcl_init_aggr.cpp
@@ -15,7 +15,7 @@ struct NonAggregate {
};
NonAggregate non_aggregate_test = { 1, 2 }; // expected-error{{non-aggregate type 'NonAggregate' cannot be initialized with an initializer list}}
-NonAggregate non_aggregate_test2[2] = { { 1, 2 }, { 3, 4 } }; // expected-error 2 {{initialization of non-aggregate type 'NonAggregate' with an initializer list}}
+NonAggregate non_aggregate_test2[2] = { { 1, 2 }, { 3, 4 } }; // expected-error 2 {{non-aggregate type 'NonAggregate' cannot be initialized with an initializer list}}
// C++ [dcl.init.aggr]p3
OpenPOWER on IntegriCloud