[Issue 9217] New: A problem with default function argument initialization

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 27 01:19:27 PST 2012


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 at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2012-12-27 01:19:26 PST ---
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: -------


More information about the Digitalmars-d-bugs mailing list