[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:53:00 PDT 2012


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



--- Comment #6 from Maxim Fomin <maxim at maxim-fomin.ru> 2012-10-05 09:41:09 PDT ---
(In reply to comment #5)
> (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.

Agree here, but I was talking about that it is logically that those asserts
should fail, rather than about accepting non-lvalue default arguments.

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