On Thu, 19 May 2011 00:22:42 -0400, Jonathan M Davis <jmdavisp...@gmx.com> wrote:

On 2011-05-18 20:55, %u wrote:
Hi!

Is this a bug, or is it intentional that this fails? I can't come up
with any case where it would cause a problem, but the compiler doesn't
like the fact that there's a const in the structure:

    struct Temp { const int a; int b; }

    auto ref foo(Temp* t) { return *t; } //Error

As soon as you do *t, you're copying the value.

That's not true, if it's ref, it just copies the reference.

example:

void foo(ref int i) { i = 5; }

void main()
{
   int i;
   int *p = &i;
   foo(*p);
   assert(i == 5);
}

To further drive home the point, this actually compiles:


Temp foo(Temp* t) { return *t; } // no error

There should be no restrictions on returning ref there, no matter what's inside Temp.

Definitely a bug with the original, please file with bugzilla.

-Steve

Reply via email to