Return by 'ref' problems...

Jonathan M Davis jmdavisProg at gmx.com
Fri May 4 15:45:00 PDT 2012


On Friday, May 04, 2012 23:26:37 Peter Alexander wrote:
> On Friday, 4 May 2012 at 08:46:38 UTC, Jonathan M Davis wrote:
> > On Friday, May 04, 2012 11:38:32 Manu wrote:
> >> I try rearranging the syntax to make the first issue stop
> >> complaining:
> >> 
> >> ref const(Thing) func2() { return gThing; } // this seems to
> >> work now, but
> >> i don't like the inconsistency...
> > 
> > That's thanks to the nonsense that putting const on the
> > left-hand side of a
> > member function is legal, making it so that you _must_ use
> > parens with const
> > and return types for the const to apply to the return type
> > rather than the
> > function.
> 
> It's not only legal, sometimes it's required, e.g. if you want
> type inference on a const member function.
> 
> class Foo
> {
> auto fun() { ... } //ok
> auto fun() const { ... } // error, two storage classes
> fun() const { ... } // error, expected storage class before
> 'foo'
> const fun() { ... } // correct!
> }

Yuck. Personally, I _really_ don't think that allowing const as a function 
attribute on the left-hand side of a function is worth the cost, even if does 
theoretically make make const consistant with the other function attributes.

- Jonathan M Davis


More information about the Digitalmars-d mailing list