D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6091 - [d-p-l.org] Description for "Modifier casting" is misleading
Summary: [d-p-l.org] Description for "Modifier casting" is misleading
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dlang.org (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-02 12:36 UTC by Steven Schveighoffer
Modified: 2012-01-20 22:21 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-06-02 12:36:08 UTC
From this page: http://d-programming-language.org/expression.html

------
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.
------

When I read this, I interpret casting to a CastQual as only *adding* the given modifiers, but it actually *replaces* the modifiers.

For example:

shared int x;
assert(is(typeof(cast(const)x) == const int));

Note, shared is *removed* from the modifiers.

For the second statement, casting with ( ) removes shared as well:

shared int x;
assert(is(typeof(cast()x) == int));

Finally, "Casting to the empty ( )" reads poorly.

I would say "Cast with no Type or CastQual inside the parentheses has the effect of removing any top level const, immutable, or shared type modifiers from the type of the UnaryExpression."

I also would like to see examples here, feel free to use my two above.