diff options
author | dim <dim@FreeBSD.org> | 2011-07-17 15:40:56 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-07-17 15:40:56 +0000 |
commit | 611ba3ea3300b71eb95dc4e45f20eee5dddd32e1 (patch) | |
tree | 2097d084eb235c0b12c0bff3445f4ec7bbaa8a12 /test/SemaCXX/generalized-initializers.cpp | |
parent | c49018d9cce52d8c9f34b44865ec3ba8e89a1488 (diff) | |
download | FreeBSD-src-611ba3ea3300b71eb95dc4e45f20eee5dddd32e1.zip FreeBSD-src-611ba3ea3300b71eb95dc4e45f20eee5dddd32e1.tar.gz |
Vendor import of clang trunk r135360:
http://llvm.org/svn/llvm-project/cfe/trunk@135360
Diffstat (limited to 'test/SemaCXX/generalized-initializers.cpp')
-rw-r--r-- | test/SemaCXX/generalized-initializers.cpp | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/test/SemaCXX/generalized-initializers.cpp b/test/SemaCXX/generalized-initializers.cpp index ec37a0c..6e2bee7 100644 --- a/test/SemaCXX/generalized-initializers.cpp +++ b/test/SemaCXX/generalized-initializers.cpp @@ -85,23 +85,52 @@ namespace integral { namespace objects { + struct X1 { X1(int); }; + struct X2 { explicit X2(int); }; + template <int N> struct A { A() { static_assert(N == 0, ""); } A(int, double) { static_assert(N == 1, ""); } - A(int, int) { static_assert(N == 2, ""); } A(std::initializer_list<int>) { static_assert(N == 3, ""); } }; - void initialization() { + template <int N> + struct D { + D(std::initializer_list<int>) { static_assert(N == 0, ""); } // expected-note 1 {{candidate}} + D(std::initializer_list<double>) { static_assert(N == 1, ""); } // expected-note 1 {{candidate}} + }; + + template <int N> + struct E { + E(int, int) { static_assert(N == 0, ""); } + E(X1, int) { static_assert(N == 1, ""); } + }; + + void overload_resolution() { { A<0> a{}; } { A<0> a = {}; } - { A<1> a{1, 1.0}; } - { A<1> a = {1, 1.0}; } + // Narrowing conversions don't affect viability. The next two choose + // the initializer_list constructor. + { A<3> a{1, 1.0}; } // expected-error {{narrowing conversion}} + { A<3> a = {1, 1.0}; } // expected-error {{narrowing conversion}} { A<3> a{1, 2, 3, 4, 5, 6, 7, 8}; } { A<3> a = {1, 2, 3, 4, 5, 6, 7, 8}; } { A<3> a{1, 2, 3, 4, 5, 6, 7, 8}; } { A<3> a{1, 2}; } + + { D<0> d{1, 2, 3}; } + { D<1> d{1.0, 2.0, 3.0}; } + { D<-1> d{1, 2.0}; } // expected-error {{ambiguous}} + + { E<0> e{1, 2}; } + } + + void explicit_implicit() { + { X1 x{0}; } + { X1 x = {0}; } + { X2 x{0}; } + { X2 x = {0}; } // expected-error {{explicit}} } struct C { @@ -172,3 +201,28 @@ namespace litb { B g({1, 2, 3}); } + +namespace aggregate { + // Direct list initialization does NOT allow braces to be elided! + struct S { + int ar[2]; + struct T { + int i1; + int i2; + } t; + struct U { + int i1; + } u[2]; + struct V { + int var[2]; + } v; + }; + + void test() { + S s1 = { 1, 2, 3 ,4, 5, 6, 7, 8 }; // no-error + S s2{ {1, 2}, {3, 4}, { {5}, {6} }, { {7, 8} } }; // completely braced + S s3{ 1, 2, 3, 4, 5, 6 }; // xpected-error + S s4{ {1, 2}, {3, 4}, {5, 6}, { {7, 8} } }; // xpected-error + S s5{ {1, 2}, {3, 4}, { {5}, {6} }, {7, 8} }; // xpected-error + } +} |