When is a dynamic array really a static array?

Steven Schveighoffer schveiguy at gmail.com
Mon Dec 30 15:39:00 UTC 2019


What do you think this should print?

import std.stdio;

void foo(size_t N)(ubyte[N])
{
     writeln("static");
}

void foo()(ubyte[])
{
     writeln("dynamic");
}

void main()
{
     ubyte[16] x;
     foo(x);
     foo(x[]);
}

Up until 2.068.2 (possibly 2.068.0), this printed:

static
dynamic

Since 2.068.2 it now prints

static
static

Why? Is there a good reason for this, or should it be a regression? I 
always thought if you sliced a static array, that became a dynamic array.

Note that doing this:

auto y = x[];
foo(y);

does print dynamic as I expected.

The context for this is https://issues.dlang.org/show_bug.cgi?id=16519. 
I wanted to say in there "at least there's a workaround, just slice the 
input". But I guess that doesn't work!

-Steve


More information about the Digitalmars-d mailing list