[cfe-commits] r135176 - /cfe/trunk/test/SemaCXX/generalized-initializers.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Thu Jul 14 12:08:01 PDT 2011
Author: cornedbee
Date: Thu Jul 14 14:08:01 2011
New Revision: 135176
URL: http://llvm.org/viewvc/llvm-project?rev=135176&view=rev
Log:
Fix problems Johannes noticed, and extend test cases further.
Modified:
cfe/trunk/test/SemaCXX/generalized-initializers.cpp
Modified: cfe/trunk/test/SemaCXX/generalized-initializers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/generalized-initializers.cpp?rev=135176&r1=135175&r2=135176&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/generalized-initializers.cpp (original)
+++ cfe/trunk/test/SemaCXX/generalized-initializers.cpp Thu Jul 14 14:08:01 2011
@@ -85,23 +85,52 @@
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 @@
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
+ }
+}
More information about the cfe-commits
mailing list