[Issue 9665] Structure constant members can not be initialized if have opAssign

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 9 09:47:59 PST 2013


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



--- Comment #6 from Maksim Zholudev <maximzms at gmail.com> 2013-03-09 09:47:58 PST ---
(In reply to comment #1)
> But for non-mutable field, opAssign invocation is not legal, because it may
> break const correctness.
> 
> T* p;
> struct T {
>    void opAssign(int n) { ...; p = &this; }
> }
> struct S {
>    immutable T field;
>    this(...) { field = 1;  // invoke T.opAssign (currently not allowed)
>       /* now global p holds mutable pointer to immutable T object! */
>    }
> }

Is there any way to break const correctness if opAssign is pure?

If not, then changes should be allowed for pure opAssign (e.g. with implicit
cast field to mutable).

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