[Issue 6427] Templated ctor cannot set immutable member variables

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 2 11:06:44 PDT 2011


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


Jonathan M Davis <jmdavisProg at gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg at gmx.com


--- Comment #1 from Jonathan M Davis <jmdavisProg at gmx.com> 2011-08-02 11:06:42 PDT ---
1. This compiles with the current compiler on github.

2. I'm not even 100% sure this is supposed to compile, since the constructor
isn't immutable. That might only be necessary when the whole struct is
immutable though. I don't remember for sure and would have to check in TDPL
(which I don't have on me at the moment).

3. While this should certainly compile correctly based on the language spec (or
not compile depending on the spec). I would serious advise against having const
or immutable variables in a struct, since you can then never assign to them
even if they're not const or immutable. If they're on the heap, it's not as big
a deal, but a struct like S would be useless in arrays (since all of the values
would be stuck as S.init) and every instance of it would be effectively
immutable regardless of whether the object itself was typed as immutable or
not.

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