Skip to content

Commit 523e9d9

Browse files
authored
fix dlang/dmd!21476: Presence of move constructor causes overload error (dlang/dmd!21477)
Move constructors were incorrectly being considered as regular constructors, which resulted in the test case failing with: ``` compilable/test21476.d(12): Error: none of the overloads of `this` are callable using argument types `(string)` auto o = S21476("aoe"); ^ compilable/test21476.d(6): Candidates are: `test21476.S21476.this(ref return scope S21476)` this(ref return scope S21476); ^ compilable/test21476.d(7): `test21476.S21476.this(return scope S21476)` this(return scope S21476); ^ ``` With this change, a struct literal is now used to construct the object.
1 parent 65cf2b6 commit 523e9d9

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

dmd/dstruct.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ extern (C++) class StructDeclaration : AggregateDeclaration
307307
}
308308
if (auto ctorDecl = s.isCtorDeclaration())
309309
{
310-
if (!ctorDecl.isCpCtor && (!ignoreDisabled || !(ctorDecl.storage_class & STC.disable)))
310+
if (!ctorDecl.isCpCtor && !ctorDecl.isMoveCtor && (!ignoreDisabled || !(ctorDecl.storage_class & STC.disable)))
311311
{
312312
result = true;
313313
return 1;

dmd/func.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,8 @@ extern (C++) final class CtorDeclaration : FuncDeclaration
13731373

13741374
override const(char)* kind() const
13751375
{
1376-
return isCpCtor ? "copy constructor" : "constructor";
1376+
return isCpCtor ? "copy constructor" :
1377+
isMoveCtor ? "move constructor" : "constructor";
13771378
}
13781379

13791380
override bool isVirtual() const

tests/dmd/compilable/test21476.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// https://github.com/dlang/dmd/issues/21476
2+
3+
struct S21476
4+
{
5+
string field;
6+
this(ref return scope S21476);
7+
this(return scope S21476);
8+
}
9+
10+
void test21476()
11+
{
12+
auto o = S21476("aoe");
13+
}

0 commit comments

Comments
 (0)