]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/fail_compilation/test20245.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / fail_compilation / test20245.d
1 /*
2 REQUIRED_ARGS: -preview=dip1000
3 TEST_OUTPUT:
4 ---
5 fail_compilation/test20245.d(14): Error: scope variable `a` may not be returned
6 fail_compilation/test20245.d(18): Error: cannot take address of `scope` parameter `x` in `@safe` function `foo`
7 fail_compilation/test20245.d(33): Error: reference to local variable `price` assigned to non-scope `this.minPrice`
8 ---
9 */
10
11 // https://issues.dlang.org/show_bug.cgi?id=20245
12 @safe int* foo(ref int x) {
13 int* a = &x;
14 return a;
15 }
16
17 @safe int** foo(ref scope int* x) {
18 int** a = &x;
19 return a;
20 }
21
22 @safe int* foo(return ref int x) {
23 int* a = &x;
24 return a;
25 }
26
27 // https://issues.dlang.org/show_bug.cgi?id=21212
28 class MinPointerRecorder
29 {
30 int* minPrice;
31 void update(ref int price) @safe
32 {
33 minPrice = &price; // Should not compile.
34 }
35 }
36
37 void main() @safe
38 {
39 auto r = new MinPointerRecorder;
40 () { int mp = 42; r.update(mp); } ();
41 () { ulong[1000] stomp = 13; } ();
42 auto x = *r.minPrice; // "13"
43 }