Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.brendan/init3.C

raw
1 // { dg-do run }
2 // GROUPS passed initialization
3 // p2766: Make sure that members are initialized in order of declaration
4 // in the class, not in order of specification in the mem-initializer list.
5
6 extern "C" int printf (const char *, ...);
7 extern "C" void exit (int);
8
9 int count = 0;
10
11 void die () { printf ("FAIL\n"); exit (1); }
12
13 class bar1 {
14 public:
15 bar1 (int) { if (count != 0) die (); count = 1; }
16 };
17
18 class bar2
19 {
20 public:
21 bar2 (int) { if (count != 1) die (); count = 2; }
22 };
23
24 class foo
25 {
26 public:
27 bar1 a;
28 bar2 b;
29 foo (int, int);
30 };
31
32 // bar1 should get built before bar2
33 foo::foo (int x, int y) : b(x), a(y) {}
34
35 int main()
36 {
37 foo f (1, 2);
38 printf ("PASS\n");
39 }