https://issues.dlang.org/show_bug.cgi?id=12936
Issue ID: 12936 Summary: Some more @nogc cases for immediately iterated array literal Product: D Version: D2 Hardware: x86 OS: Windows Status: NEW Severity: enhancement Priority: P1 Component: DMD Assignee: nob...@puremagic.com Reporter: bearophile_h...@eml.cc This is a spinoff of Issue 12932 See this code: struct F { int x; } void main() @nogc { foreach ( a; [F(1)]) {} // Case#1 OK foreach (int[1] a; [[1]]) {} // Case#2 Error foreach (const ref int[1] a; [[1]]) {} // Case#3 Error foreach ( a; [[1]]) {} // Case#4 Error } With dmd2.066alpha gives: test.d(4,25): Error: array literal in @nogc function main may cause GC allocation test.d(5,5): Error: argument type mismatch, int[] to ref const(int[1]) test.d(6,25): Error: array literal in @nogc function main may cause GC allocation Currently the Case#1 works. I think Case#2 could work because it's supposed to be a dynamic array of int[1] values. I am not sure we can also support the Case#4, this is more complex, and perhaps needs escape analisys. So not supporting Case#4 is acceptable for now. Case#4 currently doesn't even compile even without @nogc, but perhaps it should without @nogc. --