Bug 14911 – Compiler found indexing in code "new MyStruct[2].ptr"
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-12T16:25:00Z
Last change time
2015-08-24T11:44:32Z
Keywords
pull
Assigned to
nobody
Creator
kdmult
Comments
Comment #0 by kdmult — 2015-08-12T16:25:27Z
The following code does not compile with dmd v2.068.0.
void main()
{
int* buf1 = new int[2].ptr; // Ok
struct MyStruct {}
MyStruct* buf2 = (new MyStruct[2]).ptr; // Ok
// Error: expected TypeTuple when indexing ('[2]'), got 'MyStruct'
MyStruct* buf3 = new MyStruct[2].ptr;
}
Comment #1 by dfj1esp02 — 2015-08-13T09:02:12Z
Oh, did it work? AFAIK, D grammar never allowed to parse (new A.B) as (new A).B, that would require semantic analysis before parsing.
(In reply to Sobirari Muhomori from comment #1)
> Oh, did it work? AFAIK, D grammar never allowed to parse (new A.B) as (new
> A).B, that would require semantic analysis before parsing.
http://dlang.org/changelog.html#postfix-new
Comment #4 by k.hara.pg — 2015-08-13T10:17:29Z
(In reply to kdmult from comment #3)
> (In reply to Sobirari Muhomori from comment #1)
> > Oh, did it work? AFAIK, D grammar never allowed to parse (new A.B) as (new
> > A).B, that would require semantic analysis before parsing.
>
> http://dlang.org/changelog.html#postfix-new
Until 2.067, compiler parser had recognized `MyStruct[2].` for the new-ed type, and `.ptr` was parsed as dot-identifier expression.
In 2.068, the issue 1215 fix had (accidentally) changed parser behavior, to make the whole part of `MyStruct[2].ptr` as the new-ed type. Then semantic analysis is failing to find such the type.
Comment #5 by github-bugzilla — 2015-08-23T10:10:19Z