summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/opt/static6.C
blob: 00e76fb73503ec58d1a67e6653d0d3138b234310 (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
// PR c++/31806
// { dg-do run }
// { dg-options "-O2 -fno-inline -fno-threadsafe-statics" }

extern "C" void abort(void);

struct A
{
    void *d;
};

static const A& staticA()
{
    static A s_static;
    return s_static;
}

void assert_failed()
{
    abort();
}

A testMethod()
{
    static const A& s = staticA( );
    if (&s == 0)
        assert_failed();
    return s;
}

int main()
{
    testMethod();
    return 0;
}