April 24, 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@puremagic.com
          Reporter: duser@neet.fi
                CC: duser@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();
}

--