Thread overview
[Issue 5223] New: [qtd] Cannot use default value with function parameter of struct type
Nov 16, 2010
Max Samukha
Nov 16, 2010
Max Samukha
Dec 18, 2012
Andrej Mitrovic
Feb 10, 2013
Andrej Mitrovic
November 16, 2010
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


--- Comment #0 from Max Samukha <samukha@voliacable.com> 2010-11-16 09:36:29 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: -------
November 16, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5223



--- Comment #1 from Max Samukha <samukha@voliacable.com> 2010-11-16 09:48:10 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: -------
December 18, 2012
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


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-18 12:44:39 PST ---
(In reply to comment #1)
> 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: -------
February 10, 2013
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


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-02-10 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: -------