[Issue 21525] New: Spurious "copying &... into allocated memory escapes a reference to parameter variable" with associative array iteration

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 5 00:29:33 UTC 2021


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

          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 at puremagic.com
          Reporter: dlang-bugzilla at 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
(https://github.com/dlang/dmd/pull/10805).

--


More information about the Digitalmars-d-bugs mailing list