Bug 10917 – scope ref should be allowed

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-28T15:22:00Z
Last change time
2013-08-28T15:31:50Z
Keywords
rejects-valid
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2013-08-28T15:22:18Z
----- void foo(scope int* val) { } // ok void bar(scope ref int val) { } // error void main() { int x; foo(&x); // ok bar(x); } ----- 'scope ref int' is almost the same thing as 'scope int*', except that 'ref' cannot be null, and 'ref' is simpler to use in code since a user can copy by value with the assignment syntax instead of having to dereference the pointer first. Note that addresses can be extracted from both pointers and references: ----- int* ptr; void foo(scope int* val) { ptr = val; // disallowed once scope is properly implemented } void bar(/*scope*/ ref int val) { ptr = &val; // equivalent to &main.x } void main() { int x; foo(&x); bar(x); } ----- So scope ref is very much useful to have. And yeah, I realize scope does practically nothing in the compiler right now (e.g. http://forum.dlang.org/thread/[email protected]#post-mailman.391.1348770797.5162.digitalmars-d-learn:40puremagic.com).
Comment #1 by andrej.mitrovich — 2013-08-28T15:31:50Z
Thanks to eco for reporting the dupe. *** This issue has been marked as a duplicate of issue 8121 ***