[Issue 18949] New: Array literals don't work with betterc

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 6 00:55:10 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18949

          Issue ID: 18949
           Summary: Array literals don't work with betterc
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: johnnymarler at gmail.com

--- bug.d
void takeArray(const(int)[] array)
{
}
void bar()
{
    takeArray([1, 2, 3]);
}


> dmd -c -betterc bug.d

bug.d(6): Error: `TypeInfo` cannot be used with -betterC


It looks like passing an array literal to a function parameter creates a
dependency on `TypeInfo`.  It think this has to do with how D is handling the
array literal.  It might be trying to allocate it using the GC which is causing
it to depend on GC.  You can make the example work if you change bar to the
following:

void bar()
{
    static arr = [1, 2, 3];
    takeArray(arr);
}

However, I think both versions should work. Otherwise, a better error message
should be in order, i.e.

bug.d(6): dynamic array literals are not supported in betterC.  you can fix
this by assigning the array to a static variable instead.

--


More information about the Digitalmars-d-bugs mailing list