[Issue 10952] struct ctor with defaulted parameters should not be allowed

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Sep 2 10:09:42 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10952



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-09-02 10:09:41 PDT ---
Additionally I'm curious about the class situation:

class C
{
    this(int x = 1) { assert(0); }
}

According to the DMDFE, this is *not* a default ctor, and yet, it's the only
one generated in the assembly code. What exactly is the terminology for a
default constructor (with regards to defaulted parameters)?

It's also interesting that Object.factory returns null if you have any ctor,
even one with with a defaulted parameter:

-----
class C
{
    this(int x = 1) { }
}

import std.stdio;

void main()
{
    auto c = Object.factory("test.C");
    assert(c !is null);  // fails
}
-----

So we have the situation where:
auto s = S();  // works, but doesn't call the user ctor
auto c = new C();  // works AND calls the user ctor
Object.factory("test.C");  // works only if there's no user-ctor, even one with
default parameters

This is an inconsistent mess.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list