www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10917] New: scope ref should be allowed

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10917

           Summary: scope ref should be allowed
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-08-28
15:22:18 PDT ---
-----
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/rbgssjrzdcmbhxyhwlak forum.dlang.org#post-mailman.391.1348770797.5162.digitalmars-d-learn:40puremagic.com).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 28 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10917


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-08-28
15:31:50 PDT ---
Thanks to eco for reporting the dupe.

*** This issue has been marked as a duplicate of issue 8121 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 28 2013