Bug 2120 – scope class spec unclear

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-05-21T10:47:37Z
Last change time
2019-08-20T11:50:35Z
Assigned to
Walter Bright
Creator
david

Comments

Comment #0 by davidl — 2008-05-21T10:47:37Z
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); }
Comment #1 by shro8822 — 2008-05-21T11:11:42Z
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.
Comment #2 by bugzilla — 2008-05-22T05:11:10Z
Classes are by reference, not by value. This is by design, and the behavior you are seeing is typical reference semantics. Not a bug.
Comment #3 by davidl — 2008-05-22T05:48:13Z
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. }
Comment #4 by davidl — 2008-05-22T05:49:24Z
umm, the bug is no longer about the assignment. the bug is about the spec.