summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/fail_compilation/test20149.d
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gdc.test/fail_compilation/test20149.d')
-rw-r--r--gcc/testsuite/gdc.test/fail_compilation/test20149.d34
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/testsuite/gdc.test/fail_compilation/test20149.d b/gcc/testsuite/gdc.test/fail_compilation/test20149.d
new file mode 100644
index 00000000000..af99a59d7e0
--- /dev/null
+++ b/gcc/testsuite/gdc.test/fail_compilation/test20149.d
@@ -0,0 +1,34 @@
+/* REQUIRED_ARGS: -preview=dip1000
+ * TEST_OUTPUT:
+---
+fail_compilation/test20149.d(28): Error: escaping reference to stack allocated value returned by `S('\xff').this(1)`
+---
+*/
+
+// https://issues.dlang.org/show_bug.cgi?id=20149#c10
+
+@safe:
+
+struct S
+{
+ this(int){ }
+
+ char[] opSlice() return
+ {
+ return buf[];
+ }
+
+ char[4] buf;
+}
+
+S bar();
+
+char[] fun()
+{
+ return S(1)[];
+}
+
+void main()
+{
+ auto x = fun();
+}