[Issue 23052] New: importC: assigning array compound-literal to pointer allocates using GC
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Apr 24 22:52:39 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23052
Issue ID: 23052
Summary: importC: assigning array compound-literal to pointer
allocates using GC
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: ImportC
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: duser at neet.fi
CC: duser at neet.fi
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();
}
--
More information about the Digitalmars-d-bugs
mailing list