[dmd-beta] rvalue references

Jonathan M Davis jmdavisProg at gmx.com
Tue Apr 10 20:11:57 PDT 2012


On Wednesday, April 11, 2012 10:23:44 kenji hara wrote:
> Agreed. Introducing *rvalue reference* requires such changes for
> consistency. But, again, keep all literals rvalue, please.

Indeed. It's incredibly inconsistent for struct literals to be lvalues. 
Literals should always be rvalues. Allowing references to them with something 
like const& like in C++ is of value, but that's of value with _all_ 
temporaries. struct literals should not be treated specially from other 
literals or temporaries. Having

void func(ref S s) {}
S foo() {}
func(S(1)); //succeeds
func(foo()); //fails

is atrocious. It's incredibly inconsistent and confusing. S(1) should treated 
identically as the return value of foo().

If we need to continue to allow struct literals to be lvalues just for this 
release in order to restrict code breakage while we sort out how we're going 
to deal with const ref and rvalues, then that's fine, as undesirable as it may 
be, but struct literals should _not_ be lvalues in the long run.

- Jonathan M Davis


More information about the dmd-beta mailing list