digitalmars.D.bugs - [Issue 3757] New: The overload and override issue of const/immutable member functions -2nd-
- d-bugmail puremagic.com (48/48) Jan 30 2010 http://d.puremagic.com/issues/show_bug.cgi?id=3757
- d-bugmail puremagic.com (9/9) Oct 30 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3757
- d-bugmail puremagic.com (36/36) Oct 31 2011 http://d.puremagic.com/issues/show_bug.cgi?id=3757
- d-bugmail puremagic.com (10/10) Jan 28 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3757
- d-bugmail puremagic.com (9/9) Jan 28 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3757
- d-bugmail puremagic.com (9/9) Jan 28 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3757
- d-bugmail puremagic.com (9/9) Jan 28 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3757
- d-bugmail puremagic.com (9/9) Jan 28 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3757
- d-bugmail puremagic.com (15/16) Jan 28 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3757
- d-bugmail puremagic.com (20/20) Jan 28 2012 http://d.puremagic.com/issues/show_bug.cgi?id=3757
http://d.puremagic.com/issues/show_bug.cgi?id=3757
Summary: The overload and override issue of const/immutable
member functions -2nd-
Product: D
Version: 2.040
Platform: Other
OS/Version: Windows
Status: NEW
Keywords: spec
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: rayerd.wiz gmail.com
Depends on: 3282
PST ---
import std.stdio;
class Base
{
string f()
{
return "Base.f()";
}
}
class Derived : Base
{
string f()
{
return "Derived.f()";
}
string f() const
{
return "Derived.f() const";
}
}
void main()
{
auto x = new Base;
writeln(x.f());
auto y = new Derived;
writeln(y.f());// calls "Derived.f() const", but it is expected that be
called non-const.
auto z = new const(Derived);
writeln(z.f());
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3757
Haruki Shigemori <rayerd.wiz gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 30 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3757
Steven Schveighoffer <schveiguy yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|spec |wrong-code
Status|RESOLVED |REOPENED
CC| |schveiguy yahoo.com
Version|2.040 |D2
Resolution|INVALID |
Summary|The overload and override |Overloading const function
|issue of const/immutable |with overridden non-const
|member functions -2nd- |function results in seg
| |fault.
OS/Version|Windows |All
08:02:36 PDT ---
This is neither invalid nor fixed. Tested in Linux 32-bit.
Tested with 2.055:
Base.f()
Derived.f() const
Derived.f() const
Tested with 2.056:
Base.f()
Derived.f()
Segmentation fault
Clearly there is some invalid vtable stuff going on here. Probably was going
on before, but manifested in a different way. If I remove the base class from
the picture, it correctly prints out:
Derived.f()
Derifed.f() const
Expected printout for original code should be:
Base.f()
Derived.f()
Derived.f() const
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 31 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3757
Walter Bright <bugzilla digitalmars.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bugzilla digitalmars.com
00:17:42 PST ---
This is an undiagnosed error. Both Derived.f functions override Base.f.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 28 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3757 Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/588feaeaee1342984f5f53be762fdbc198cd112d fix Issue 3757 - Overloading const function with overridden non-const function results in seg fault. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 28 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3757 Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/04e632617be33cce3e92b5d48a7fa20a6ca621fb fix Issue 3757 - Overloading const function with overridden non-const function results in seg fault. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 28 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3757 Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/470080a7735309b804920954b892ef615bb972de fix Issue 3757 - Overloading const function with overridden non-const function results in seg fault. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 28 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3757
Walter Bright <bugzilla digitalmars.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution| |FIXED
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 28 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3757
timon.gehr gmx.ch changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
CC| |timon.gehr gmx.ch
Resolution|FIXED |
This is an undiagnosed error. Both Derived.f functions override Base.f.
The first Derived.f overrides Base.f, the second is an additionally introduced
overload. According to http://www.d-programming-language.org/function , this
should not be a compile error but behave as stated in the bug report.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 28 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3757
timon.gehr gmx.ch changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution| |FIXED
On second thought, I might be wrong. The spec states:
- "Virtual functions all have a hidden parameter called the this reference,
which refers to the class object for which the function is called."
- "A functions in a derived class with the same name and parameter types as a
function in a base class overrides that function:"
If the type of the hidden parameter was included in the "parameter types" part
of the second statement, no function would override another, therefore it
apparently is not. Therefore the commit indeed fixed the discrepancy with the
spec. I think the design should be revisited at some point to make overriding
more intuitive and powerful.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 28 2012









d-bugmail puremagic.com 