www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3757] New: The overload and override issue of const/immutable member functions -2nd-

reply d-bugmail puremagic.com writes:
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


--- Comment #0 from Haruki Shigemori <rayerd.wiz gmail.com> 2010-01-30 19:30:03
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
next sibling parent d-bugmail puremagic.com writes:
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
prev sibling next sibling parent d-bugmail puremagic.com writes:
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


--- Comment #1 from Steven Schveighoffer <schveiguy yahoo.com> 2011-10-31
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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3757


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2012-01-28
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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3757



--- Comment #3 from github-bugzilla puremagic.com 2012-01-28 00:23:19 PST ---
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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3757



--- Comment #4 from github-bugzilla puremagic.com 2012-01-28 00:24:10 PST ---
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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3757



--- Comment #5 from github-bugzilla puremagic.com 2012-01-28 00:24:41 PST ---
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
prev sibling next sibling parent d-bugmail puremagic.com writes:
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
prev sibling next sibling parent d-bugmail puremagic.com writes:
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                       |


--- Comment #6 from timon.gehr gmx.ch 2012-01-28 13:21:17 PST ---
(In reply to comment #2)
 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
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3757


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #7 from timon.gehr gmx.ch 2012-01-28 14:05:08 PST ---
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