www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17784] New: [scope][DIP1000] Confusing error message for


          Issue ID: 17784
           Summary: [scope][DIP1000] Confusing error message for escaping
                    local via new-expression
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: petar.p.kirov gmail.com

With PR https://github.com/dlang/dmd/pull/7101, given the following code:
#line 1300

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

void test1300()  safe
    int i;
    auto p = new S1300(&i).oops; // line 1306

struct S1300
    int* oops;
//    this(int* p)  safe { oops = p; }

The compiler produces the following error message:
scope_test.d(1306): Error: returning `& i` escapes a reference to local
variable `i`

Which is confusing to the user, because there are no return statements in the
whole file. I suggest the following error message:

scope_test.d(1306): Error: reference to local variable `i` assigned to
heap-allocated `S1300.oops` with possibly longer lifetime

Aug 26 2017