cast()x - a valid expression?

Stewart Gordon smjg_1998 at yahoo.com
Fri Jun 3 16:33:36 PDT 2011


On 01/06/2011 21:51, Steven Schveighoffer wrote:
> On Wed, 01 Jun 2011 16:38:42 -0400, KennyTM~ <kennytm at gmail.com> wrote:
<snip>
>> cast(const), cast(immutable) etc are documented. cast() is not. See
>> http://d-programming-language.org/expression.html#CastExpression

What is that site?  A reference for how the compiler actually behaves, as opposed to the spec?

> :O
>
> Of course, by documented, it shows the cast in the grammar (BTW, why the separate rule for
> cast(Type) when CastParam can be Type?), but not in the text. I almost never read the
> grammar unless I'm confused by the docs.
>
> This is almost as good as const_cast, although it seems too easy to screw up and remove
> const when you don't want to.

And it's a puzzling notation.  Nobody would guess what it means.  As such, it looks like a 
bug that the compiler accepts the code.

See also previous discussions about making casting away const/immutable explicit:
http://tinyurl.com/4x7wpy9
http://tinyurl.com/4xotq3o

Stewart.


More information about the Digitalmars-d mailing list