[Issue 3449] const and invariant struct members do not behave according to spec

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 30 06:39:07 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3449



--- Comment #3 from Stewart Gordon <smjg at iname.com> 2009-10-30 06:39:03 PDT ---
(In reply to comment #2)
> (In reply to comment #1)
>> (In reply to comment #0)
>>> and in the case of const it is even considered well-defined 
>>> behaviour to change their value after casting them to non-const.
>> 
>> What bit of the spec is this?  Are you sure you aren't confusing D 
>> with C(++)?
> 
> You're right, I got things mixed up there.  :)
> 
> On the "const and immutable" page there is a section named 
> "Removing Immutable With A Cast", where it says that "The immutable 
> type can be removed with a cast [...] This does not mean, however, 
> that one can change the data".  It says nothing about const, which 
> was what led me to believe that changing consts is not illegal, at 
> least.

Since immutable is implicitly convertible to const, it's reasonable that the
same rule should apply to const.

My guess is that the reason for being able to cast away const/immutable is to
interface APIs that take pointers to mutable because they _may_ change the
data, but which can be controlled not to.  The Windows API function DrawTextEx
is an example of this.

But I do wish the means of casting away const/immutable were explicit - see
http://tinyurl.com/yzzbgdn

> But I see now that the D/C++ comparison table at the bottom of the 
> page has a similar statement for consts.
> 
> But the rest still stands: It should be possible to take the 
> address of both consts and immutables.

Agreed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list