D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3365 - Safe casts: type modifiers
Summary: Safe casts: type modifiers
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-05 07:11 UTC by anonymous4
Modified: 2015-06-09 05:13 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 anonymous4 2009-10-05 07:11:53 UTC
C++ has const_cast to add or remove const modifier from type. Currently in D casting to/from const is unsafe as it doesn't protect from type conversions. Safe variants of const casts can be added with the following syntax:

cast(const)obj; //to const-qualified
cast(~const)obj; //to mutable
cast(immutable)obj; //instead of assumeUnique
cast(~immutable)obj;
cast(shared)obj;
cast(~shared)obj;

I'm not sure whether cast(~const) should behave exactly as cast(~immutable).

P.S. This doesn't impose any additional requirement on the runtime library.
Comment 1 Infiltrator 2014-03-18 22:15:01 UTC
This is available in the language as of 2.065 (and earlier; but you would have to dig for yourself.)