Bug 2788 – return val not passable via ref const in other method
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-04-02T21:00:18Z
Last change time
2019-08-12T13:15:39Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Stephan Dilly
Comments
Comment #0 by spam — 2009-04-02T21:00:18Z
This used work perfectly fine, why not anymore ? (since 2.027)
[CODE]
int getVar()
{
return 2;
}
void foo(ref const int _p)
{}
void main()
{
foo(getVar());
}
[/CODE]
Error: function main.foo (ref const const(int) _p) does not match parameter types (int)
Error: getVar() is not an lvalue
Comment #1 by hoganmeier — 2011-03-01T06:28:43Z
ref const doesn't make any sense with basic types.
But it makes sense for struct and static array temporaries.
The weird thing is struct literals count as lvalues in D2, so this works:
struct A {}
void foo(ref A a) {}
void main()
{
foo(A());
}
while calling the following doesn't:
static A bar()
{
return A();
}
foo(bar());
Comment #2 by razvan.nitu1305 — 2019-08-12T13:15:39Z
`getVar()` is an rvalue, therefore it cannot be passed to a ref parameter. Therefore the bug report is invalid.
>struct A {}
>void foo(ref A a) {}
>void main()
>{
> foo(A());
>}
This doesn't compiler and neither does this:
>static A bar()
>{
> return A();
>}
>
>foo(bar());
Closing as invalid.