Bug 6200 – [GSoC] Value returned by function cannot be passed as ref const.

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2011-06-23T12:23:00Z
Last change time
2011-06-23T13:15:13Z
Assigned to
nobody
Creator
cristi.cobzarenco

Comments

Comment #0 by cristi.cobzarenco — 2011-06-23T12:23:27Z
struct Test {} void takes( ref const Test x ) {} Test gives() { return Test(); } int main() { takes( Test() ); // compiles // takes( gives() ); // doesn't compile readln(); return 0; } Is this required behaviour? The compiler complains about gives() not being an lvalue, but the code doesn't seem to require it to be an lvalue.
Comment #1 by kennytm — 2011-06-23T13:03:36Z
No 'ref' does require the parameter as an lvalue, even if 'const' is present. This is different from C++. I think it's a duplicate of bug 3167. Also, the struct literal 'Test()' currently returns an lvalue, not an rvalue. See bug 5889.
Comment #2 by cristi.cobzarenco — 2011-06-23T13:08:14Z
(In reply to comment #1) > No 'ref' does require the parameter as an lvalue, even if 'const' is present. > This is different from C++. I think it's a duplicate of bug 3167. > > Also, the struct literal 'Test()' currently returns an lvalue, not an rvalue. > See bug 5889. Aha, I guess you're right, I assumed that const would fix it (bug 3167 only talks about normal refs), 'in' works though.
Comment #3 by kennytm — 2011-06-23T13:11:37Z
(In reply to comment #2) > (In reply to comment #1) > > No 'ref' does require the parameter as an lvalue, even if 'const' is present. > > This is different from C++. I think it's a duplicate of bug 3167. > > > > Also, the struct literal 'Test()' currently returns an lvalue, not an rvalue. > > See bug 5889. > > Aha, I guess you're right, I assumed that const would fix it (bug 3167 only > talks about normal refs), 'in' works though. Bug 3167 does talk about 'const ref' in the later comments, e.g. http://d.puremagic.com/issues/show_bug.cgi?id=3167#c12.
Comment #4 by cristi.cobzarenco — 2011-06-23T13:15:13Z
(In reply to comment #3) > (In reply to comment #2) > > (In reply to comment #1) > > > No 'ref' does require the parameter as an lvalue, even if 'const' is present. > > > This is different from C++. I think it's a duplicate of bug 3167. > > > > > > Also, the struct literal 'Test()' currently returns an lvalue, not an rvalue. > > > See bug 5889. > > > > Aha, I guess you're right, I assumed that const would fix it (bug 3167 only > > talks about normal refs), 'in' works though. > > Bug 3167 does talk about 'const ref' in the later comments, e.g. > http://d.puremagic.com/issues/show_bug.cgi?id=3167#c12. You're right again, sorry. I looked through the comments, but somehow didn't see that one. I'll mark this as invalid.