From: Sebastian Redl Date: Thu, 14 Jul 2011 19:08:01 +0000 (+0000) Subject: Fix problems Johannes noticed, and extend test cases further. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc998b44454eb39fa39d701712cb8f448f2612c1;p=clang Fix problems Johannes noticed, and extend test cases further. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135176 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/SemaCXX/generalized-initializers.cpp b/test/SemaCXX/generalized-initializers.cpp index ec37a0c9ac..6e2bee7e30 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 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) { static_assert(N == 3, ""); } }; - void initialization() { + template + struct D { + D(std::initializer_list) { static_assert(N == 0, ""); } // expected-note 1 {{candidate}} + D(std::initializer_list) { static_assert(N == 1, ""); } // expected-note 1 {{candidate}} + }; + + template + 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 + } +}