]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/fail_compilation/fail20183.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / fail_compilation / fail20183.d
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 */
9
10 #line 1000
11
12 // https://issues.dlang.org/show_bug.cgi?id=20183
13
14 @safe:
15
16 int* addr(return ref int b) { return &b; }
17
18 struct S
19 {
20 int i;
21 }
22
23 S s() { return S(); }
24
25 void test()
26 {
27 int* p = addr(S().i); // struct literal
28 int* q = addr(s().i); // struct temporary
29 }
30
31 /*
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 ---
36 */
37 #line 1100
38
39 class Foo
40 {
41 int* ptr;
42
43 this() @safe
44 {
45 ptr = addr(s().i); // struct literal
46 }
47 }