www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21525] New: Spurious "copying &... into allocated memory


          Issue ID: 21525
           Summary: Spurious "copying &... into allocated memory escapes a
                    reference to parameter variable" with associative
                    array iteration
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: diagnostic, rejects-valid
          Severity: regression
          Priority: P3
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

/////////////////////////////// test.d ///////////////////////////////
void main()
    int[string] aa;
    aa["name"] = 5;

    int*[] pvalues;
    foreach (name, ref value; aa)
        // Deprecation: copying `&value` into allocated memory escapes
        // a reference to parameter variable `value`
        pvalues ~= &value;

    // The reference is, in fact, valid.
    *pvalues[0] = 7;
    assert(aa["name"] == 7);

The error message, besides apparently being spurious, is additionally
misleading: `value` is not a parameter as far as the programmer is concerned.

This is a regression caused by enabling DIP25 by default

Jan 04 2021