OSDN Git Service

PR tree-optimization/53239
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / special / initp1.C
1 /* { dg-do run { target init_priority } } */
2 #include <stdlib.h>
3
4 class Two {
5 private:
6     int i, j, k;
7 public:
8     static int count;
9     Two( int ii, int jj ) { i = ii; j = jj; k = count++; };
10     Two( void )           { i =  0; j =  0; k = count++; };
11     int eye( void ) { return i; };
12     int jay( void ) { return j; };
13     int kay( void ) { return k; };
14 };
15
16 extern Two foo;
17 extern Two goo;
18 extern Two coo[];
19 extern Two koo[];
20
21 Two foo __attribute__((init_priority(1005))) ( 5, 6 );
22
23 Two goo __attribute__((init_priority(1007))) = Two( 7, 8 );
24
25 Two doo[ 3 ];
26
27 Two hoo[ 3 ] = {
28     Two( 11, 12 ),
29     Two( 13, 14 ),
30     Two( 15, 16 )
31 };
32
33 Two coo[ 3 ] __attribute__((init_priority(1000)));
34
35 Two koo[ 3 ] __attribute__((init_priority(1000))) = {
36     Two( 21, 22 ),
37     Two( 23, 24 ),
38     Two( 25, 26 )
39 };
40
41 Two xoo[ 3 ] __attribute__((init_priority(1100)));
42
43 Two zoo[ 3 ] __attribute__((init_priority(1100))) = {
44     Two( 31, 32 ),
45     Two( 33, 34 ),
46     Two( 35, 36 )
47 };
48
49 int Two::count;
50
51 long x = 0;
52
53 #define X( n ) \
54   do { if ( x & (1L << (n)) ) return 1; else x |= (1L << (n)); } while (0)
55
56 int main()
57 {
58
59     X( coo[0].kay() );
60     X( coo[1].kay() );
61     X( coo[2].kay() );
62     X( koo[0].kay() );
63     X( koo[1].kay() );
64     X( koo[2].kay() );
65     if ( 0x3f != x ) abort ();
66
67     X( foo.kay() );
68     if ( 0x7f != x ) abort ();
69
70     X( goo.kay() );
71     if ( 0xff != x ) abort ();
72
73     X( xoo[0].kay() );
74     X( xoo[1].kay() );
75     X( xoo[2].kay() );
76     X( zoo[0].kay() );
77     X( zoo[1].kay() );
78     X( zoo[2].kay() );
79     if ( 0x3fff != x ) abort ();
80
81     X( doo[0].kay() );
82     X( doo[1].kay() );
83     X( doo[2].kay() );
84     X( hoo[0].kay() );
85     X( hoo[1].kay() );
86     X( hoo[2].kay() );
87     if ( 0xfffff != x ) abort ();
88
89     exit (0);
90 }