www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2712] New: error with passing an array slot as another array length to new

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2712

           Summary: error with passing an array slot as another array length
                    to new
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: andrei metalanguage.com


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]


-- 
Mar 06 2009
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2712


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Version|unspecified                 |1.00


--- Comment #1 from Don <clugdbug yahoo.com.au> 2010-01-27 02:43:25 PST ---
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]);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 27 2010