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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 4 21:44:06 PDT 2012


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


Maxim Fomin <maxim at maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim at maxim-fomin.ru


--- Comment #4 from Maxim Fomin <maxim at maxim-fomin.ru> 2012-10-04 21:32:15 PDT ---
(In reply to comment #1)
> Ow.
> 
> Even this fails:
> 
> void test1(ref int val = 10) {}
> void test2(out int val = 20) {}
> void main() {
>     int x;
>     test1(x);
>     assert(x == 10);
>     test2(x);
>     assert(x == 20);
> }

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.

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