view gcc/testsuite/g++.dg/opt/static6.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
line wrap: on
line source

// 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;
}