Bug 18949 – Array literals don't work with betterc

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-06-06T00:55:10Z
Last change time
2022-12-27T12:00:55Z
Keywords
betterC
Assigned to
No Owner
Creator
Jonathan Marler
See also
https://issues.dlang.org/show_bug.cgi?id=16037

Comments

Comment #0 by johnnymarler — 2018-06-06T00:55:10Z
--- 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.
Comment #1 by dfj1esp02 — 2018-06-06T13:49:21Z
Technically it needs `in` attribute: --- void takeArray(in int[] array) { } void bar() { takeArray([1, 2, 3]); } ---
Comment #2 by nick — 2022-12-27T12:00:55Z
`array` needs to be `in` or `scope`. The error message has been improved: arrlit.d(6): Error: expression `[1, 2, 3]` uses the GC and cannot be used with switch `-betterC`