Issue 14911 - Compiler found indexing in code "new MyStruct[2].ptr"
Summary: Compiler found indexing in code "new MyStruct[2].ptr"
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2015-08-12 16:25 UTC by kdmult
Modified: 2015-08-24 11:44 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kdmult 2015-08-12 16:25:27 UTC
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 anonymous4 2015-08-13 09:02:12 UTC
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.
Comment 3 kdmult 2015-08-13 09:53:36 UTC
(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 Kenji Hara 2015-08-13 10:17:29 UTC
(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 github-bugzilla 2015-08-23 10:10:19 UTC
Commit pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c1d8b528477bdda68128826454b92be643760e53
fix Issue 14911 - Compiler found indexing in code "new MyStruct[2].ptr"
Comment 6 github-bugzilla 2015-08-24 11:44:32 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c1d8b528477bdda68128826454b92be643760e53
fix Issue 14911 - Compiler found indexing in code "new MyStruct[2].ptr"