d: Merge upstream dmd, druntime 4c18eed967, phobos d945686a4.
[official-gcc.git] / gcc / testsuite / gdc.test / fail_compilation / fail20183.d
blob8a08844f8432372379c22628fb19f42b6b69cbd1
1 /* REQUIRED_ARGS: -preview=dip1000
2 TEST_OUTPUT:
3 ---
4 fail_compilation/fail20183.d(1016): Error: function `fail20183.addr(return ref int b)` is not callable using argument types `(int)`
5 fail_compilation/fail20183.d(1016): cannot pass rvalue argument `S(0).i` of type `int` to parameter `return ref int b`
6 fail_compilation/fail20183.d(1017): Error: address of struct temporary returned by `s()` assigned to longer lived variable `q`
7 ---
8 */
10 #line 1000
12 // https://issues.dlang.org/show_bug.cgi?id=20183
14 @safe:
16 int* addr(return ref int b) { return &b; }
18 struct S
20 int i;
23 S s() { return S(); }
25 void test()
27 int* p = addr(S().i); // struct literal
28 int* q = addr(s().i); // struct temporary
32 TEST_OUTPUT:
33 ---
34 fail_compilation/fail20183.d(1107): Error: address of struct temporary returned by `s()` assigned to longer lived variable `this.ptr`
35 ---
37 #line 1100
39 class Foo
41 int* ptr;
43 this() @safe
45 ptr = addr(s().i); // struct literal