[Issue 7603] Default initializer for ref/out must be an lvalue

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 5 09:42:40 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7603



--- Comment #5 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2012-10-05 09:30:41 PDT ---
(In reply to comment #4)
> Why wouldn't this fail? Default arguments are used if no argument is given.
> Sine you provide arguments and functions don't modify them, arguments are not
> changed. The only modification happens due to parameter storage class out.
> 
>  void test1(ref int val = 10) {}
>  void test2(out int val = 20) {}
>  void main() {
>      int x = 5;
>      test1(x);
>      assert(x == 5);
>      test2(x);
>      assert(x == 0);
> }
> 
> Passes both assertions as it should.

Ignoring what bear's confusion here, the function declaration is invalid. Call
test1() alone:

void test1(ref int val = 10) { }
void main()
{
    test1();  // Error: constant 10 is not an lvalue
}

It makes no sense adding default arguments if they'll never compile, so this
needs to be a CT error when the function is parsed and not when the function is
called.

-- 
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