D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2712 - error with passing an array slot as another array length to new
Summary: error with passing an array slot as another array length to new
Status: RESOLVED DUPLICATE of issue 783
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-03-06 15:59 UTC by Andrei Alexandrescu
Modified: 2014-02-15 13:13 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2009-03-06 15:59:22 UTC
void foo(uint n, in uint[] x)
{
    auto y = new uint[x[n]];
}

void main()
{
    foo(new uint[10]);
}

Error: need size of rightmost array, not type x[n]
Comment 1 Don 2010-01-27 02:43:25 UTC
This is a parsing error. Workaround: Adding () around the x[n] allows it to compile.

void foo(uint n, in uint[] x) {
    auto y = new uint[ (x[n]) ];
}

void main() {
    foo(7, new uint[10]);
}
Comment 2 yebblies 2012-02-01 07:28:52 UTC

*** This issue has been marked as a duplicate of issue 783 ***