cast()x - a valid expression?

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 2 03:10:17 PDT 2011


On Thu, 02 Jun 2011 01:32:52 -0400, Walter Bright  
<newshound2 at digitalmars.com> wrote:

> On 6/1/2011 12:22 PM, KennyTM~ wrote:
>> But this is not documented in the D spec (CastParam cannot be empty).  
>> Is this an
>> "accept-invalid" bug, or just a feature not yet documented?
>
> A feature that coincidentally just got documented :-)
>

Seems incorrect:

Casting to a CastQual adds the qualifier to the type of the  
UnaryExpression.

Casting to the empty ( ) has the effect of removing any top level const or  
immutable type modifiers from the type of the UnaryExpression.

 From these descriptions, I would expect the following asserts to pass:

const int a;
auto b = cast(shared)a; // add shared to the type
assert(is(typeof(b) == shared const int));

shared const int x;
auto y = cast()x; // remove const or immutable from the type
assert(is(typeof(y) == shared int));

But both fail.  Seems like both expressions set the modifiers to their  
args.

-Steve


More information about the Digitalmars-d mailing list