The following code:
```
void test () // L1
{
string[] foo;
auto f = () { assert(foo[0] == "HellO"); }; // L4
foo ~= "HellO"; // L5
}
```
Compiled with `dmd -c -vgc test.d` gives the following output:
```
test.d(5): vgc: operator ~= may cause GC allocation
test.d(1): vgc: using closure causes GC allocation
```
So the appending has the right line, but not the closure allocation.
Comment #1 by k.hara.pg — 2016-05-18T16:18:44Z
The shown line number is not wrong.
The closure environment that is closing variable foo, is allocated at the start of function test() == line 1. The delegate literal at line 4 just refers it.
So, the issue would be:
1. the message text that is not enough helpful (diagnostic), or
2. lack of information about the location where the closed variable 'foo' is used from (enhancement).
Comment #2 by robert.schadek — 2024-12-13T18:47:49Z