digitalmars.D.bugs - [Issue 1645] New: can override base class' const method with non-const method
- d-bugmail puremagic.com (50/50) Nov 07 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1645
- d-bugmail puremagic.com (10/10) Oct 21 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1645
- d-bugmail puremagic.com (9/9) Apr 01 2009 http://d.puremagic.com/issues/show_bug.cgi?id=1645
http://d.puremagic.com/issues/show_bug.cgi?id=1645 Summary: can override base class' const method with non-const method Product: D Version: 2.007 Platform: All OS/Version: All Status: NEW Keywords: accepts-invalid Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: schveiguy yahoo.com This should not be allowed. Otherwise, you can call a const method on a base class and the derived class can change the object. I believe the fix that should be implemented should follow the same rules as today's override rules. i.e., same function name/args, but derived method has different const specicification results in a different signature, and therefore a different overload. Here is code that demonstrates the issue: import std.stdio; class A { int x; const void f() { writefln("A"); } } class B : A { override void f() { x = 2; writefln("B"); } } void main(){ A y = new B; y.f; } [steves localhost svn]$ dmd testme.d gcc testme.o -o testme -m32 -Xlinker -L/home/steves/dmd2/dmd/bin/../lib -lphobos2 -lpthread -lm [steves localhost svn]$ ./testme B [steves localhost svn]$ --
Nov 07 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1645 schveiguy yahoo.com changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |critical ------- Comment #1 from schveiguy yahoo.com 2008-10-21 10:57 ------- Bumping the severity up. This really is a terrible bug, especially since we are getting closer and closer to pure functions. This bug has existed way too long. --
Oct 21 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1645 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED ------- Comment #2 from bugzilla digitalmars.com 2009-04-01 13:51 ------- Fixed DMD 2.027 --
Apr 01 2009