Bug 6297 – cast() does not remove const or immutable on arrays and pointers
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-07-12T11:46:14Z
Last change time
2024-05-16T18:06:44Z
Assigned to
No Owner
Creator
Steven Schveighoffer
Comments
Comment #0 by schveiguy — 2011-07-12T11:46:14Z
cast() is supposed to remove all attributes from a type, but in the case of arrays, it does nothing to the tail.
I think cast() should remove even the tail.
Note that arrays *already* implicitly cast to their tail versions. i.e.:
const(T[]) implicitly casts to const(T)[]
immutable(T[]) implicitily casts to immutable(T)[]
so to have:
cast()const(T[]) result in const(T)[] serves no purpose, I need no cast there.
The same goes for pointers, and if they are ever implemented, tail-const object references.
Comment #1 by nick — 2024-05-16T12:55:03Z
The spec (now) says:
> Casting with no type or qualifiers removes any top level const, immutable, shared or inout type modifiers from the type of the UnaryExpression
https://dlang.org/spec/expression.html#cast_qualifier
Note 'top level'. So I think this is invalid.
Comment #2 by schveiguy — 2024-05-16T18:06:44Z
I have no idea what I was thinking those 13 years ago. OK to close ;)