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;
f()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;
g()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
h()31 void h ()
32 {
33 int arr[] = { 1, 1, 1, 1, 1, 1, 1 };
34 g ();
35 }
36
main()37 int main ()
38 {
39 g ();
40 h ();
41 return r;
42 }
43