diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2011-07-14 19:08:01 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2011-07-14 19:08:01 +0000 |
commit | 771ee369660e932f31338adbb445c9de70dbf830 (patch) | |
tree | a63b62cb64972e1b349db90a1b0d805a2251aa7a | |
parent | 112aa826c72821bc090f5a679be656f0f79ee384 (diff) | |
download | bcm5719-llvm-771ee369660e932f31338adbb445c9de70dbf830.tar.gz bcm5719-llvm-771ee369660e932f31338adbb445c9de70dbf830.zip |
Fix problems Johannes noticed, and extend test cases further.
llvm-svn: 135176
-rw-r--r-- | clang/test/SemaCXX/generalized-initializers.cpp | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/clang/test/SemaCXX/generalized-initializers.cpp b/clang/test/SemaCXX/generalized-initializers.cpp index ec37a0c9ac1..6e2bee7e301 100644 --- a/clang/test/SemaCXX/generalized-initializers.cpp +++ b/clang/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 + } +} |