[Issue 18478] Spurious "escapes a reference to local variable" error in function that does not return by reference

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 16 15:08:07 UTC 2018


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

Carsten Blüggel <chilli at posteo.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid, spec

--- Comment #1 from Carsten Blüggel <chilli at posteo.net> ---
Another error example from phobos that appeared in master within the last ~24h:
https://github.com/dlang/phobos/blob/master/std/exception.d

make -f posix.mak std/exception.test (-dip1000 for that module; DMD64 master)

std/exception.d(1243): Error: returning & i escapes a reference to local
variable i

excerpt from std/exception.d:

/// Arrays (dynamic and static)
@system unittest
{
    int i;
    int[]  slice = [0, 1, 2, 3, 4];
    int[5] arr   = [0, 1, 2, 3, 4];
    int*[]  slicep = [&i];               <= line 1243
    int*[1] arrp   = [&i];
...
    assert( slicep[0].doesPointTo(i));   <= slicep usage
    assert(!slicep   .doesPointTo(i));   <= slicep usage
...

1. This is @system code, allowed to escape whatever
2. There is no escape (commenting out slicep usages doesn't change error
reported)

--


More information about the Digitalmars-d-bugs mailing list