--- Comment #2 from Andrej Mitrovic <> 2012-10-04 
10:34:29 PDT ---
(In reply to comment #0)
> void test1(ref bool val = true) {
> }
> void test2(out bool val = true) {
> }

Actually I'm only half-right. Phobos uses this in std.random:

void randomShuffle(Range, RandomGen = Random)(Range r, ref RandomGen gen =

So 'val' is either a reference to a passed-in argument, or a reference to the
default argument which is an lvalue.

Default argument for 'ref' parameter should only be allowed if the argument is
an lvalue ('true' is an rvalue'). The compiler already checks this but *only*
if the function is called without arguments:

void test(ref bool val = true) { }

void main()
    bool b;
    test(b); // ok, no errors
    test();  // errors only on this invocation

The compiler should error as soon as it sees the invalid declaration. I'll make
a pull shortly.

Btw, the same applies to 'out'. An rvalue isn't valid, but an lvalue as default
argument is perfectly valid:

bool w = true;
void test(out bool val = w) { }

void main()
    assert(w == false);

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to