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.
Comment #2 by k.hara.pg — 2012-12-24T00:48:46Z
Comment #3 by github-bugzilla — 2012-12-24T01:30:27Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/2bbb33df2fa9f87ae73de6924031e1a854756ea1 Additional fix for issue 6905 For the inference of return value ref-ness, we should use 'auto ref' instead of 'ref' or 'const ref' https://github.com/D-Programming-Language/phobos/commit/03a6e295fadd7c563a60069be0be3ada1c234666 Merge pull request #1028 from 9rnsr/fix6905 Additional fix for issue 6905
Comment #4 by github-bugzilla — 2013-01-08T20:09:35Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/251885197ac9470c65807f739ea49cdc983c5a3e fix Issue 6905 - ref acts as auto ref when return type is missing https://github.com/D-Programming-Language/dmd/commit/f193abd3a39759f432197ba9f37e48518fb4499a Merge pull request #1401 from 9rnsr/fix6905 Issue 6905 - ref acts as auto ref when return type is missing