[Issue 4251] Hole in the const system: immutable values can be overwritten (const(T) is appendable to const(T)[])
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Nov 18 07:11:12 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4251
--- Comment #18 from Steven Schveighoffer <schveiguy at yahoo.com> 2011-11-18 07:10:20 PST ---
(In reply to comment #17)
> (In reply to comment #16)
> > B x;
> > A* y=&x; // bad!
> Everything you describe is supposed to happen. "A* y = &x" is the point of
> inheritance. What exactly is the problem you see in the above? All of your
> assert elements seem fine too…
The example isn't illustrative enough.
Here's a better example:
class A {}
class B : A {void foo() {writeln("hello, B");} }
void main()
{
B x;
A* y = &x;
*y = new A;
x.foo(); // boom! Call to invalid vtable entry
}
As I said in an earlier comment, this bug is really a dup of bug 2095, but it
adds a different twist. If we want to consolidate, we should close this as a
duplicate of 2095.
> Reverting title. This bug is about the const safety design of the language, not
> about inheritance. Even if there is a problem with inheritance, it should be a
> separate bug unless you can argue they have the same cause.
It's somewhat the same thing. const(T) is really a "base class" of T, since T
implicitly casts to const(T), but const(T) doesn't implicitly cast to T.
I won't revert the bug description again, because I think this case is already
covered in 2095.
--
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