www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5223] New: [qtd] Cannot use default value with function parameter of struct type

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

           Summary: [qtd] Cannot use default value with function parameter
                    of struct type
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: samukha voliacable.com



PST ---
Struct constructors are disregarded when a struct parameter is constructed out
of a default value:

struct S2
{
}

struct S
{
    int x;

    this(S2 s2)
    {
    }

    void foo(S s = S(S2))
    {
    }
}

void main()
{
    S s;
    s.foo(); // error
}

Error: cannot implicitly convert expression (S2()) of type S2 to int.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5223




PST ---
Even simpler test-case:

struct S
{
    this(int x)
    {
    }

    void foo(S s = S(42))
    {
    }
}

void main()
{
    S s;
    s.foo(); // error
}

Error: more initializers than fields of S

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5223


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



12:44:39 PST ---

 Even simpler test-case:
This is very similar to Issue 3206. I think what's probably happening is that the semantic analysis on the call expression in a default argument is done without completing the semantic analysis on the struct/class first. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 18 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5223


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|Other                       |All
           See Also|                            |http://d.puremagic.com/issu
                   |                            |es/show_bug.cgi?id=6766
         OS/Version|Linux                       |All



09:05:19 PST ---
Also same problem for classes:
http://d.puremagic.com/issues/show_bug.cgi?id=6766

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