/////////////////////////////// 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).
@RazvanN7 created dlang/dmd pull request #12173 "Fix Issue 21525 - Spurious copying into allocated memory escapes a reβ¦" fixing this issue: - Fix Issue 21525 - Spurious copying into allocated memory escapes a reference to parameter variable with associative array iteration https://github.com/dlang/dmd/pull/12173
I cannot reproduce this. I think it has been fixed.