www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10952] New: struct ctor with defaulted parameters should not be allowed

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10952

           Summary: struct ctor with defaulted parameters should not be
                    allowed
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



09:59:30 PDT ---
-----
struct S
{
    this(int x = 1) { assert(0); }  // never throws
}

void main()
{
    auto s = S();
}
-----

If we're really never going to support user-provided default ctors (like it is
now), then the above should become a compile-time error. That default argument
can't be used.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 02 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10952




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: -------
Sep 02 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10952


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



12:15:53 PDT ---
*** This issue has been marked as a duplicate of issue 3438 ***

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