* doc/extend.texi: Document optional priority argument to
[official-gcc.git] / gcc / testsuite / g++.dg / special / initp1.C
blob4a539a5a4bdd851a33fcb6b653741c4411450428
1 /* { dg-do run { target init_priority } } */
2 #include <stdlib.h>
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; };
16 extern Two foo;
17 extern Two goo;
18 extern Two coo[];
19 extern Two koo[];
21 Two foo __attribute__((init_priority(1005))) ( 5, 6 );
23 Two goo __attribute__((init_priority(1007))) = Two( 7, 8 );
25 Two doo[ 3 ];
27 Two hoo[ 3 ] = {
28     Two( 11, 12 ),
29     Two( 13, 14 ),
30     Two( 15, 16 )
33 Two coo[ 3 ] __attribute__((init_priority(1000)));
35 Two koo[ 3 ] __attribute__((init_priority(1000))) = {
36     Two( 21, 22 ),
37     Two( 23, 24 ),
38     Two( 25, 26 )
41 Two xoo[ 3 ] __attribute__((init_priority(1100)));
43 Two zoo[ 3 ] __attribute__((init_priority(1100))) = {
44     Two( 31, 32 ),
45     Two( 33, 34 ),
46     Two( 35, 36 )
49 int Two::count;
51 long x = 0;
53 #define X( n ) \
54   do { if ( x & (1L << (n)) ) return 1; else x |= (1L << (n)); } while (0)
56 int main()
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 ();
67     X( foo.kay() );
68     if ( 0x7f != x ) abort ();
70     X( goo.kay() );
71     if ( 0xff != x ) abort ();
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 ();
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 ();
89     exit (0);