Bug 19010 – new fails on dynamic array aliases

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-06-21T00:36:22Z
Last change time
2020-03-21T03:56:42Z
Assigned to
No Owner
Creator
elpenguino+D

Comments

Comment #0 by elpenguino+D — 2018-06-21T00:36:22Z
Pretty simple example: ``` unittest { alias T = int[]; T t = new T; } ``` This doesn't seem to have ever compiled correctly. It currently fails with the misleading error "Error: new can only create structs, dynamic arrays or class objects, not int[]'s"
Comment #1 by ag0aep6g — 2018-06-21T16:04:14Z
The alias has nothing to do with the error. This gives the same error: ---- unittest { int[] t = new int[]; /* Error: new can only create structs, dynamic arrays or class objects, not int[]'s */ } ---- (In reply to elpenguino+D from comment #0) > This doesn't seem to have ever compiled correctly. As far as I know, `new int[]` is not supposed to compile. The spec [1] is a bit scarce on this, but `new`ing arrays is only mentioned with explicit lengths. [1] https://dlang.org/spec/expression.html#new_expressions
Comment #2 by b2.temp — 2018-06-21T16:28:04Z
Grammartically it's valid (it's the first new rule, i.e `new AllocatorArgumentsopt Type`) but since `new` for arrays doesn't return a pointer to an array, allowing this would be a bit pointless because `int[] a = new int[];` would be the same as `int[] a;`
Comment #3 by b2.temp — 2019-12-12T19:39:18Z
The problem is actually a bad diagnostic. This is like 20422, i.e the length parameter misses. *** This issue has been marked as a duplicate of issue 20422 ***