www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6931] New: scope parameter storage class not checked at all

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

           Summary: scope parameter storage class not checked at all
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid, diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: mrmocool gmx.de



int ga;
C gb;
S* gc;
int[] gd;

struct S {}
class C {}

void foo(scope int a, scope C b, scope S* c, scope int[] d)
{
    ga = a;
    gb = b;
    gc = c;
    gd = d;
    ga = d[1];
}

void main()
{
    S s;
    foo(5, new C, &s, [1,2,3]);
}

This compiles and runs fine. Shouldn't at least some of these cause errors?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 11 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6931


Denis <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg gmail.com



---
If we will look at destruction & allocation:
---
import std.stdio;

class C {
    int n;
    this(int n) { writefln(" this(%s) at %s", this.n = n, cast(void*)this); }
    ~this() { writefln("~this(%s) at %s", n, cast(void*)this); }
}

void main() {
    int i;
    writefln("Stack is at %s", &i);
    writefln("Heap  is at %s", (new void[1]).ptr);
    {
        C cHeap = new C(0); // will be destroyed on scope exit
        scope C c0 = cHeap;

        // C(1)-C(4) will be allocated in heap
        // C(1), C(2), and C(4) will be destroyed on scope exit
        // C(3) will be destroyed on garbage collection
        scope C c1 = cast(C)cast(void*)new C(1);
        scope C c2 = true ? new C(2) : null;
        scope C c3 = (new C(3), new C(4));
    }
    writefln("after scope");
}
---
As a result even if `C` is a `scope class` the program will compile without
`cHeap` and `c0`, but every `C` instance will be allocated in heap and C(3)
will be destroyed on garbage collection.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6931




This report is about scope as a parameter storage class!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6931




---
Oh, sorry for the unrelated comment. Created Issue 7347 for that.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2012