[Issue 21369] New: Compiler doesn't allow lvalues via alias this when wrapper is an rvalue
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Nov 7 14:35:32 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21369
Issue ID: 21369
Summary: Compiler doesn't allow lvalues via alias this when
wrapper is an rvalue
Product: D
Version: D2
Hardware: x86
OS: Mac OS X
Status: NEW
Keywords: rejects-valid
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: schveiguy at yahoo.com
Consider the following struct:
struct S
{
int *val;
ref int get() { return *val; }
}
void foo(ref int x) {}
void main()
{
int x;
foo(S(&x).get);
}
This builds fine. However, using alias this to forward to the get function:
struct S
{
int *val;
ref int get() { return *val; }
alias get this;
}
void foo(ref int x) {}
void main()
{
int x;
foo(S(&x));
}
I get:
onlineapp.d(15): Error: function onlineapp.foo(ref int x) is not callable using
argument types (S)
onlineapp.d(15): cannot pass rvalue argument S(& x) of type S to
parameter ref int x
Clearly, the alias this should work, especially since if I call the aliased
member directly it does work.
This is a block for creating correct smart reference types.
--
More information about the Digitalmars-d-bugs
mailing list