Bug 21525 – Spurious "copying &... into allocated memory escapes a reference to parameter variable" with associative array iteration
Status
RESOLVED
Resolution
WORKSFORME
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-01-05T00:29:33Z
Last change time
2023-02-28T10:36:31Z
Keywords
diagnostic, pull, rejects-valid
Assigned to
No Owner
Creator
Vladimir Panteleev
Comments
Comment #0 by dlang-bugzilla — 2021-01-05T00:29:33Z
/////////////////////////////// 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).
Comment #1 by dlang-bot — 2021-02-01T16:20:03Z
@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
Comment #2 by razvan.nitu1305 — 2023-02-28T10:36:31Z
I cannot reproduce this. I think it has been fixed.