Bug 3365 – Safe casts: type modifiers

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-10-05T07:11:00Z
Last change time
2015-06-09T05:13:49Z
Assigned to
nobody
Creator
dfj1esp02

Comments

Comment #0 by dfj1esp02 — 2009-10-05T07:11:53Z
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 by lt.infiltrator — 2014-03-18T22:15:01Z
This is available in the language as of 2.065 (and earlier; but you would have to dig for yourself.)