Bug 23052 – importC: assigning array compound-literal to pointer allocates using GC

Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-04-24T22:52:39Z
Last change time
2023-04-09T05:52:42Z
Keywords
ImportC
Assigned to
No Owner
Creator
duser

Comments

Comment #0 by duser — 2022-04-24T22:52:39Z
void fn() { void *p = (int[1]){0}; } this uses _d_arrayliteralTX() to allocate storage for the array also, with -betterC it fails to compile because "TypeInfo cannot be used with -betterC" in other compilers, the literal has "auto" storage duration so it's the same as using a local variable this test detects if the pointer is GC-allocated: int test() { void *prev; for (int i = 0; i < 2; i++) { void *curr = (int[1]){0}; // should have the same address on both loop iterations if (i == 0) prev = curr; else if (curr != prev) return 1; } return 0; } _Static_assert(test() == 0, ""); int main() { return test(); }
Comment #1 by bugzilla — 2023-04-09T05:52:42Z
This has been fixed.