www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9217] New: A problem with default function argument initialization

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

           Summary: A problem with default function argument
                    initialization
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



import std.bigint;
void foo1(BigInt x = 0) {} // Error
void foo2(BigInt y = "1") {} // Error
void main() {
    BigInt x = 0; // OK
    BigInt y = "1"; // OK
}


DMD 2.061alpha gives:

test.d(2): Error: cannot implicitly convert expression (0) of type int to
BigInt
test.d(3): Error: cannot implicitly convert expression ("1") of type string to
BigInt


Workaround:

import std.bigint;
void foo1(BigInt x = BigInt(0)) {} // OK
void foo2(BigInt y = BigInt("1")) {} // OK
void main() {
    BigInt x = 0; // OK
    BigInt y = "1"; // OK
}


This problem in some cases asks me long function signatures as workarounds. I
can't write:

void foo(Ptr!(immutable(int[10])) arr=null) {...}

I have to define a Ptr!(...) helper alias elsewhere, or to write this:

void foo(Ptr!(immutable(int[10])) arr=Ptr!(immutable(int[10])).init) {...}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 27 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9217


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |DUPLICATE



09:04:48 PST ---
*** This issue has been marked as a duplicate of issue 7019 ***

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