Merge with main truk.
[official-gcc.git] / gcc / testsuite / g++.dg / init / init-ref2.C
blob6d9448a8e9c8628aa5d26526688b7474f7d31abc
1 // Submitted by Jason Merrill <jason_merrill@redhat.com>
2 // Test for proper handling of local static references.
3 // { dg-do run }
5 int r;
7 int c;
8 int f ()
10   // Test that we only initialize i once.
11   if (++c > 1)
12     ++r;
13   return 42;
16 const int *p;
17 void g ()
19   static const int &i = f();
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;
28   p = &i;
31 void h ()
33   int arr[] = { 1, 1, 1, 1, 1, 1, 1 };
34   g ();
37 int main ()
39   g ();
40   h ();
41   return r;