Bug 2621 – ref binds to rvalues of user-defined types
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-01-27T09:44:00Z
Last change time
2015-06-09T01:31:13Z
Assigned to
bugzilla
Creator
andrei
Comments
Comment #0 by andrei — 2009-01-27T09:44:38Z
struct Struct {}
alias Struct T;
//alias int T;
T fun() { return T(); }
void gun(ref T) {}
void main()
{
gun(fun);
}
The code compiles and it shouldn't. ref should never bind to rvalues. Currently indeed it doesn't bind to rvalues of built-in type (e.g. if the alias above is switched from Struct to int the code won't compile).
Comment #1 by andrei — 2009-01-27T09:48:26Z
(In reply to comment #0)
> struct Struct {}
> alias Struct T;
> //alias int T;
>
> T fun() { return T(); }
> void gun(ref T) {}
> void main()
> {
> gun(fun);
> }
>
> The code compiles and it shouldn't. ref should never bind to rvalues. Currently
> indeed it doesn't bind to rvalues of built-in type (e.g. if the alias above is
> switched from Struct to int the code won't compile).
>
Furthermore, adding this overload should make the code work:
void gun(T) {}
Currently adding the overload results in the error message:
function test.gun called with argument types:
(Struct)
matches both:
test.gun(ref Struct _param_0)
and:
test.gun(Struct _param_0)