[Issue 17368] New: [DIP1000] scope T** implicit convertion to scope T* allow to escape pointer

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu May 4 01:57:55 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17368

          Issue ID: 17368
           Summary: [DIP1000] scope T** implicit convertion to scope T*
                    allow to escape pointer
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: mathias.lang at sociomantic.com

Code below:

```
void main () @safe
{
    getPtr();
}

void getPtr () @safe
{
    int* ptr2;
    bar(&ptr2);
    assert(ptr2 !is null, "Oops, I have a pointer to bar.value");
}

void bar (scope int** ptr2) @safe
{
    int value;
    foo(ptr2, &value);
}

// Needs to be 'return scope' so that the compiler believes 'ptr1' has longer
lifetime thatn 'ptr2'
void foo (scope int** ptr2, scope int* ptr1) @safe
{
    foobar(*ptr2, ptr1);
}

int* foobar (scope int* p1, return scope int* p2) @safe
{
    p1 = p2;
    return p2;
}
```

--


More information about the Digitalmars-d-bugs mailing list