D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22922 - Support empty array literal in -betterC
Summary: Support empty array literal in -betterC
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull
: 5788 (view as issue list)
Depends on:
Blocks:
 
Reported: 2022-03-25 04:42 UTC by andy-hanson
Modified: 2024-08-14 23:16 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description andy-hanson 2022-03-25 04:42:52 UTC
There is an unnecessary error for empty array literals when -betterC is enabled.

```
extern(C) void main() {
	int[] x = [];
	int[] y = (cast(int*) null)[0 .. 0];
}
```

Compile with `dmd a.d -betterC` and it outputs:
```
a.d(2): Error: `TypeInfo` cannot be used with -betterC
```

Since the expression `(cast(int*) null)[0 .. 0]` works, DMD should be able to translate `[]` into it without needing TypeInfo.
Comment 1 Dlang Bot 2022-04-17 21:28:00 UTC
@dkorpel created dlang/dmd pull request #14004 "Fix issue 22922 - Support empty array literal in -betterC" fixing this issue:

- Fix issue 22922 - Support empty array literal in -betterC

https://github.com/dlang/dmd/pull/14004
Comment 2 Dlang Bot 2022-04-18 10:05:36 UTC
dlang/dmd pull request #14004 "Fix issue 22922 - Support empty array literal in -betterC" was merged into master:

- eff4ab3fecdcc4596b0f300e519d27778d38434e by Dennis Korpel:
  Fix issue 22922 - Support empty array literal in -betterC

https://github.com/dlang/dmd/pull/14004
Comment 3 Dennis 2024-08-14 23:16:24 UTC
*** Issue 5788 has been marked as a duplicate of this issue. ***