gcc/testsuite/g++.dg/opt/static6.C
raw| 1 | // PR c++/31806 |
| 2 | // { dg-do run } |
| 3 | // { dg-options "-O2 -fno-inline -fno-threadsafe-statics" } |
| 4 | |
| 5 | extern "C" void abort(void); |
| 6 | |
| 7 | struct A |
| 8 | { |
| 9 | void *d; |
| 10 | }; |
| 11 | |
| 12 | static const A& staticA() |
| 13 | { |
| 14 | static A s_static; |
| 15 | return s_static; |
| 16 | } |
| 17 | |
| 18 | void assert_failed() |
| 19 | { |
| 20 | abort(); |
| 21 | } |
| 22 | |
| 23 | A testMethod() |
| 24 | { |
| 25 | static const A& s = staticA( ); |
| 26 | if (&s == 0) |
| 27 | assert_failed(); |
| 28 | return s; |
| 29 | } |
| 30 | |
| 31 | int main() |
| 32 | { |
| 33 | testMethod(); |
| 34 | return 0; |
| 35 | } |