Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/testrvaluecpctor.d

raw
1 // https://issues.dlang.org/show_bug.cgi?id=22593
2
3 /*
4 TEST_OUTPUT:
5 ---
6 fail_compilation/testrvaluecpctor.d(16): Error: cannot define both an rvalue constructor and a copy constructor for `struct Foo`
7 fail_compilation/testrvaluecpctor.d(24): Template instance `testrvaluecpctor.Foo!int.Foo.__ctor!(immutable(Foo!int), immutable(Foo!int))` creates an rvalue constructor for `struct Foo`
8 fail_compilation/testrvaluecpctor.d(24): Error: none of the overloads of `this` can construct a `immutable` object with argument types `(immutable(Foo!int))`
9 fail_compilation/testrvaluecpctor.d(18): Candidates are: `testrvaluecpctor.Foo!int.Foo.this(ref scope Foo!int rhs)`
10 fail_compilation/testrvaluecpctor.d(16): `this(Rhs, this This)(scope Rhs rhs)`
11 ---
12 */
13
14 struct Foo(T)
15 {
16 this(Rhs, this This)(scope Rhs rhs){}
17
18 this(ref scope typeof(this) rhs){}
19 }
20
21 void fail22593()
22 {
23 immutable Foo!int a;
24 a.__ctor(a);
25 }
26
27 // https://issues.dlang.org/show_bug.cgi?id=21613
28
29 /*
30 TEST_OUTPUT:
31 ---
32 fail_compilation/testrvaluecpctor.d(40): Error: cannot define both an rvalue constructor and a copy constructor for `struct Test`
33 fail_compilation/testrvaluecpctor.d(46): Template instance `testrvaluecpctor.Test.__ctor!()` creates an rvalue constructor for `struct Test`
34 ---
35 */
36
37 struct Test
38 {
39 this(ref const typeof(this) rhs){}
40 this()(const typeof(this) rhs){} // rvalue ctor
41 }
42
43 void fail21613()
44 {
45 const Test cb;
46 Test b = cb;
47 }