OSDN Git Service

2008-03-01 Douglas Gregor <doug.gregor@gmail.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / init / init-ref2.C
1 // Submitted by Jason Merrill <jason_merrill@redhat.com>
2 // Test for proper handling of local static references.
3 // { dg-do run }
4
5 int r;
6
7 int c;
8 int f ()
9 {
10   // Test that we only initialize i once.
11   if (++c > 1)
12     ++r;
13   return 42;
14 }
15
16 const int *p;
17 void g ()
18 {
19   static const int &i = f();
20
21   // Test that i points to the same place in both calls.
22   if (p && p != &i)
23     ++r;
24   // Test that if so, it points to static data.
25   if (i != 42)
26     ++r;
27
28   p = &i;
29 }
30
31 void h ()
32 {
33   int arr[] = { 1, 1, 1, 1, 1, 1, 1 };
34   g ();
35 }
36
37 int main ()
38 {
39   g ();
40   h ();
41   return r;
42 }