const attribute makes whole element const?

monarch_dodra monarchdodra at gmail.com
Mon Sep 10 02:49:48 PDT 2012


On Sunday, 9 September 2012 at 23:54:45 UTC, Jonathan M Davis
wrote:
>
> [SNIP]
>
> the default assignment operator illegal. You could overload it, 
> and as long as
> it doesn't touch any of the const member variables, it would 
> work, but the
> const member variable is stuck as it is, and anything trying to 
> mutate is
> illegal.
>
> [SNIP]
>
> - Jonathan M Davis

Not to that it is my goal to be a pain, but the example I
provided *does* overload opAssign (and the CC), but it *doesn't*
work.

Notice the error message is:
"Error: tests[4] isn't mutable"
Which is simply not true.

The default assignment operator, when trying to do an assignment 
creates:
"Error: variable XXX cannot modify struct with immutable members."
But that is not what we are seeing.

It appears that when writting:
tests[4] = Test("Foobar");
It *looks* like compiler is eliding the opAssign/CC completely,
opting for a bit copy, which is illegal.


More information about the Digitalmars-d-learn mailing list