Bug 9739 – Regression (1.077 git-head): DMD not considering ctor with default args as default ctor
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2013-03-16T20:06:00Z
Last change time
2013-04-13T14:58:51Z
Keywords
rejects-valid
Assigned to
nobody
Creator
puneet
Comments
Comment #0 by puneet — 2013-03-16T20:06:54Z
Compiles with 2.062. But with the latest github snapshot, gives me an error:
$ rdmd --force test.d
test.d(5): Error: class test.Bar Cannot implicitly generate a default ctor when base class test.Foo is missing a default ctor
Failed: 'dmd' '-v' '-o-' 'test.d' '-I.'
class Foo {
this(int arg=0) { }
}
class Bar: Foo { }
void main() {
Bar test = new Bar;
}
Comment #1 by andrej.mitrovich — 2013-03-16T20:46:04Z
This is caused by:
https://github.com/D-Programming-Language/dmd/pull/1439
I think I've already tried to change how the 'defaultCtor' field is set, but I think that change got rejected, or maybe it was part of a pull that wasn't yet merged.
In hindsight I should have written more elaborate tests.
@Kenji: Do you know why the code which sets `ad->defaultCtor = this;` doesn't check for defaulted parameters? That code is at the end of `CtorDeclaration::semantic`
Comment #2 by k.hara.pg — 2013-04-03T18:27:10Z
(In reply to comment #1)
> This is caused by:
> https://github.com/D-Programming-Language/dmd/pull/1439
>
> I think I've already tried to change how the 'defaultCtor' field is set, but I
> think that change got rejected, or maybe it was part of a pull that wasn't yet
> merged.
>
> In hindsight I should have written more elaborate tests.
>
> @Kenji: Do you know why the code which sets `ad->defaultCtor = this;` doesn't
> check for defaulted parameters? That code is at the end of
> `CtorDeclaration::semantic`
Because ad->defaultCtor should not have any parameters. Its function pointer will be stored in TypeInfo_Class.defaultConstructor, so storing `this(int arg=0)` in it would cause access violation in runtime.
https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L853https://github.com/D-Programming-Language/dmd/blob/master/src/toobj.c#L585
Comment #8 by leandro.lucarella — 2013-04-12T09:04:06Z
(In reply to comment #7)
> https://github.com/D-Programming-Language/dmd/pull/1892
Nope, doesn't work, it was a literal backport of D2 fix but D1 doesn't have resolveFuncCall(). So I guess something else needs to be done. Would probably be even better to revert the change that caused it in D1 if a better solution is hard to implement (see issue 9925).
Comment #9 by leandro.lucarella — 2013-04-12T09:24:08Z
Pull updated with a fixed fix :P
Comment #10 by github-bugzilla — 2013-04-13T10:22:29Z