OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [cpp0x/] [initlist1.C] - Blame information for rev 774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 693 jeremybenn
// Basic uses of initializer lists
2
// { dg-do run }
3
// { dg-options "-std=c++0x" }
4
 
5
#include 
6
 
7
extern "C" void abort();
8
 
9
using namespace std;
10
 
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) {} };
14
 
15
struct D
16
{
17
  int ia[3];
18
  D (initializer_list l)
19
  {
20
    const int *p = l.begin();
21
    for (int i = 0; i < 3; ++i)
22
      ia[i] = *p++;
23
  }
24
};
25
 
26
void f(C c)
27
{
28
  if (c.b.a.i != 1) abort();
29
  if (c.b.a.j != 2) abort();
30
}
31
void f(int);
32
 
33
void g(D d)
34
{
35
  if (d.ia[0] != 1 || d.ia[1] != 2 || d.ia[2] != 3)
36
    abort();
37
}
38
 
39
struct E
40
{
41
  int i, j, k;
42
};
43
 
44
void h(E e)
45
{
46
  if (e.i != 1 || e.j != 2 || e.k != 3)
47
    abort();
48
}
49
 
50
void i(initializer_list l)
51
{
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();
57
}
58
 
59
struct U { U(int, int) {} };
60
U ua[] = { { 3, 2 } };
61
 
62
int main()
63
{
64
  g({1,2,3});
65
 
66
  h({1,2,3});
67
 
68
  f({{{1,2}}});
69
  f({{A{1,2}}});
70
 
71
  i({1,2,3});
72
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.