Issue 6297 - cast() does not remove const or immutable on arrays and pointers
Summary: cast() does not remove const or immutable on arrays and pointers
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-12 11:46 UTC by Steven Schveighoffer
Modified: 2024-05-16 18:06 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Steven Schveighoffer 2011-07-12 11:46:14 UTC
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 Nick Treleaven 2024-05-16 12:55:03 UTC
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 Steven Schveighoffer 2024-05-16 18:06:44 UTC
I have no idea what I was thinking those 13 years ago. OK to close ;)