www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2120] New: scope class assignment doesn't copy the whole class content

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

           Summary: scope class assignment doesn't copy the whole class
                    content
           Product: D
           Version: 1.030
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: davidl 126.com


Not sure if following is a bug. I need the semantic of backing up a class in
the stack. 
class Scope
{
    int i;
    int j;
}

void func(Scope m)
{
    scope Scope save=m;
    m.i=4;
    assert(save.i==3);
}

void main()
{
    Scope t=new Scope;
    t.i=3;
    t.j=3;
    func(t);
}


-- 
May 21 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2120






I don't think this isn't a bug (unless I'm missing something again). In D
classes use reference semantics and I don't /think/ that adding scope to the
variable declaration changes this. Adding scope to the class declaration OTOH
will (I think).

That said, I've never used scope so I may be off in the weeds.


-- 
May 21 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2120


bugzilla digitalmars.com changed:

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





Classes are by reference, not by value. This is by design, and the behavior you
are seeing is typical reference semantics. Not a bug.


-- 
May 22 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2120


davidl 126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |





I can't find any use case of this in:
http://www.digitalmars.com/d/2.0/class.html

maybe the spec should mention when a class type is not defined as 'scope', the
instance declared with 'scope' keyword, and when a class type is defined as
'scope', the instance declared without 'scope' keyword, how the compiler will
inteprete the semantic.

Clearfying that following code:
class Scope
{
}

void func()
{
   scope Scope t = new Scope(); // t is on the stack(or not) and it will be
deleted(or not) when exit the func scope. And any assignment of instance of
other Scope instance only means the reference assignment. 
}


-- 
May 22 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2120


davidl 126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|scope class assignment      |scope class spec unclear
                   |doesn't copy the whole class|
                   |content                     |





umm, the bug is no longer about the assignment. the bug is about the spec.


-- 
May 22 2008