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 die()11void die () { printf ("FAIL\n"); exit (1); } 12 13 class bar1 { 14 public: bar1(int)15 bar1 (int) { if (count != 0) die (); count = 1; } 16 }; 17 18 class bar2 19 { 20 public: bar2(int)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 foo(int x,int y)33foo::foo (int x, int y) : b(x), a(y) {} 34 main()35int main() 36 { 37 foo f (1, 2); 38 printf ("PASS\n"); 39 } 40