summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/opt/static6.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/g++.dg/opt/static6.C')
-rw-r--r--gcc/testsuite/g++.dg/opt/static6.C35
1 files changed, 35 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/opt/static6.C b/gcc/testsuite/g++.dg/opt/static6.C
new file mode 100644
index 000000000..00e76fb73
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/static6.C
@@ -0,0 +1,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;
+}