Reset branch to trunk.
[official-gcc.git] / trunk / gcc / testsuite / g++.dg / cpp0x / initlist1.C
blobff45f7176f611b900433a66527314206eed55bda
1 // Basic uses of initializer lists
2 // { dg-do run }
3 // { dg-options "-std=c++0x" }
5 #include <initializer_list>
7 extern "C" void abort();
9 using namespace std;
11 struct A { int i,j; A(int _i,int _j): i(_i), j(_j) {} };
12 struct B { A a; B(A _a): a(_a) {} };
13 struct C { B b; C(B _b): b(_b) {} };
15 struct D
17   int ia[3];
18   D (initializer_list<int> l)
19   {
20     const int *p = l.begin();
21     for (int i = 0; i < 3; ++i)
22       ia[i] = *p++;
23   }
26 void f(C c)
28   if (c.b.a.i != 1) abort();
29   if (c.b.a.j != 2) abort();
31 void f(int);
33 void g(D d)
35   if (d.ia[0] != 1 || d.ia[1] != 2 || d.ia[2] != 3)
36     abort();
39 struct E
41   int i, j, k;
44 void h(E e)
46   if (e.i != 1 || e.j != 2 || e.k != 3)
47     abort();
50 void i(initializer_list<int> l)
52   const int *p = l.begin();
53   if (*p++ != 1) abort();
54   if (*p++ != 2) abort();
55   if (*p++ != 3) abort();
56   if (p != l.end()) abort();
59 struct U { U(int, int) {} };
60 U ua[] = { { 3, 2 } };
62 int main()
64   g({1,2,3});
66   h({1,2,3});
68   f({{{1,2}}});
69   f({{A{1,2}}});
71   i({1,2,3});