Bug 6905 – ref acts as auto ref when return type is missing
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-11-07T11:17:00Z
Last change time
2013-01-08T21:19:56Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2011-11-07T11:17:13Z
struct Foo
{
int x;
ref noReturnType()
{
return x;
}
}
void main()
{
auto foo = Foo();
foo.noReturnType = 5;
assert(foo.x == 5);
}
Should this be allowed? It doesn't make much sense, especially when you can write code like this:
struct Foo
{
ref noReturnType()
{
return 1; // does an rvalue return
}
}
void main()
{
auto foo = Foo();
auto x = foo.noReturnType();
}
This compiles and only confuses the reader.
Comment #1 by yebblies — 2012-02-01T05:30:36Z
This happens because there is no actual storage class for auto ref, it just becomes auto ref when it is both auto and ref.