summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/fail_compilation/retscope6.d
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gdc.test/fail_compilation/retscope6.d')
-rw-r--r--gcc/testsuite/gdc.test/fail_compilation/retscope6.d48
1 files changed, 42 insertions, 6 deletions
diff --git a/gcc/testsuite/gdc.test/fail_compilation/retscope6.d b/gcc/testsuite/gdc.test/fail_compilation/retscope6.d
index 7e68bfc4702..6d5807b641a 100644
--- a/gcc/testsuite/gdc.test/fail_compilation/retscope6.d
+++ b/gcc/testsuite/gdc.test/fail_compilation/retscope6.d
@@ -201,8 +201,8 @@ void hmac(scope ubyte[] secret)
/* TEST_OUTPUT:
---
-fail_compilation/retscope6.d(12011): Error: reference to local variable `x` assigned to non-scope parameter `r` calling retscope6.escape_m_20150
-fail_compilation/retscope6.d(12022): Error: reference to local variable `x` assigned to non-scope parameter `r` calling retscope6.escape_c_20150
+fail_compilation/retscope6.d(12011): Error: returning `escape_m_20150(& x)` escapes a reference to local variable `x`
+fail_compilation/retscope6.d(12022): Error: returning `escape_c_20150(& x)` escapes a reference to local variable `x`
---
*/
@@ -210,23 +210,23 @@ fail_compilation/retscope6.d(12022): Error: reference to local variable `x` assi
// https://issues.dlang.org/show_bug.cgi?id=20150
-int* escape_m_20150(int* r) @safe pure
+int* escape_m_20150(int* r) @safe pure nothrow
{
return r;
}
-int* f_m_20150() @safe
+int* f_m_20150() @safe nothrow
{
int x = 42;
return escape_m_20150(&x);
}
-const(int)* escape_c_20150(const int* r) @safe pure
+const(int)* escape_c_20150(const int* r) @safe pure nothrow
{
return r;
}
-const(int)* f_c_20150() @safe
+const(int)* f_c_20150() @safe nothrow
{
int x = 42;
return escape_c_20150(&x);
@@ -251,3 +251,39 @@ void escape_throw_20150() @safe
immutable(char)[4] str;
f_throw(str[]);
}
+
+/* TEST_OUTPUT:
+---
+fail_compilation/retscope6.d(14019): Error: scope variable `scopePtr` assigned to non-scope parameter `x` calling retscope6.noInfer23021
+fail_compilation/retscope6.d(14022): Error: scope variable `scopePtr` may not be returned
+---
+*/
+
+#line 14000
+// https://issues.dlang.org/show_bug.cgi?id=23021
+
+ref int infer23021(ref int* x) @safe pure nothrow
+{
+ return *x;
+}
+
+ref int noInfer23021(ref int* x, const(int)** escapeHole = null) @safe pure nothrow
+{
+ *escapeHole = x;
+ return *x;
+}
+
+ref int escape23021() @safe
+{
+ scope int* scopePtr;
+ int* nonScopePtr = null;
+
+ // don't infer scope
+ cast(void) noInfer23021(scopePtr); // error
+
+ // ensure we infer return scope
+ return infer23021(scopePtr); // error
+
+ // ensure we do not infer return ref
+ return infer23021(nonScopePtr); // no error
+}