[Issue 18637] New: [scope][DIP1000] "Error: returning & i escapes a reference to local variable i" where it's inappropriate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 20 09:53:33 UTC 2018


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

          Issue ID: 18637
           Summary: [scope][DIP1000] "Error: returning & i escapes a
                    reference to local variable i" where it's
                    inappropriate
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: rejects-valid, safe, spec
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: chilli at posteo.net
                CC: chilli at posteo.net

Using phobos/dip1000.mak with entry aa[std.exception]=-dip1000 (to be changed
from -dip25 to -dip1000) and running (with current, git-cloned
dmd/druntime/phobos sources) in directory phobos:

make -f posix.mak std/exception.test

results in:
...
```
T=`mktemp -d /tmp/.dmd-run-test.XXXXXX` &&                                     
                        \
  (                                                                            
                        \
    ../dmd/generated/linux/release/64/dmd -od$T -conf= -I../druntime/import  -w
-de -dip25 -m64 -fPIC -transition=complex -O -release -dip1000  -main -unittest
generated/linux/release/64/libphobos2.a -defaultlib= -debuglib= -L-ldl -cov
-run std/exception.d ;     \
    RET=$? ; rm -rf $T ; exit $RET                                             
                     \
  )
std/exception.d(1238): Error: returning & i escapes a reference to local
variable i
```
---------------

std/exception.d used to compile successfully with -dip1000 switch until ~
2018-03-15, failing since.
AFAIK,
1. This is @system code, allowed to escape whatever
2. There is no escape (commenting out slicep usages doesn't change the error
reported)


excerpt from std/exception.d:

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

https://issues.dlang.org/show_bug.cgi?id=17784 is about the wording of this
same error msg.
Here I claim for this std/exception.d case, that it's a rejects-valid.
The comment in phobos/dip1000.mak after aa[std.exception] is outdated, will
point to this new bugzilla issue later, but was identifying this same issue.

For reference: https://github.com/dlang/phobos/blob/master/std/exception.d

--


More information about the Digitalmars-d-bugs mailing list