Issue with const
Jacob Carlborg
doob at me.com
Mon Apr 9 11:02:08 PDT 2012
On 2012-04-09 19:56, Steven Schveighoffer wrote:
> Then c.data cannot be the same reference as foo.data.
>
> Counter-case:
>
> void bar( const Foo foo)
> {
> auto c = foo.clone(); // assume this works;
> *(cast(int*)c.data) = 6; // note even though I'm casting, there is no
> removal of const, so this should be defined behavior.
> }
>
> immutable int i = 5;
> const foo = new Foo(&i);
> bar(foo);
>
> assert(i == 5); // oops, it's 6!
>
> In that case, you have to clone the data as well.
>
> -Steve
Ok, I see, thanks.
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list