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