Bug 21928 – Wrong location for "array literal in @nogc function main may cause GC allocation" error
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-05-18T15:45:48Z
Last change time
2021-05-18T23:36:28Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
Vladimir Panteleev
Comments
Comment #0 by dlang-bugzilla — 2021-05-18T15:45:48Z
//////////////// test.d ////////////////
@nogc:
struct Shape
{
immutable size_t[] dims = [];
}
void main()
{
auto s = Shape(2 ~ Shape.init.dims);
}
////////////////////////////////////////
Output:
test.d(3): Error: array literal in @nogc function D main may cause a GC allocation
Seems to be a particularly bad variant of issue 21871. It misleadingly places the blame on the initializer as if it is causing a GC allocation. Instead, the error should be placed at the ~ operator.
Comment #1 by dlang-bot — 2021-05-18T16:42:23Z
@FeepingCreature updated dlang/dmd pull request #12530 "Fix issue 21928: pass Loc to Cat() explicitly." fixing this issue:
- Fix issue 21928: pass Loc to Cat() explicitly.
Use location of concatenation for newly-created array literal, in the cases element ~ literal and literal ~ element.
https://github.com/dlang/dmd/pull/12530
Comment #2 by dlang-bot — 2021-05-18T23:36:28Z
dlang/dmd pull request #12530 "Fix issue 21928: pass Loc to Cat() explicitly." was merged into master:
- d83cb7f5e50c8c0484418952e15b4d1075b45d3f by Mathis Beer:
Fix issue 21928: pass Loc to Cat() explicitly.
Use location of concatenation for newly-created array literal, in the cases element ~ literal and literal ~ element.
https://github.com/dlang/dmd/pull/12530