Jump to page: 1 2
Thread overview
[Issue 3282] New: The overload and override issue of const/immutable member functions
Oct 19, 2009
Haruki Shigemori
Jan 22, 2010
Rainer Schuetze
Jan 31, 2010
Haruki Shigemori
Jan 23, 2012
Walter Bright
Jan 23, 2012
Walter Bright
Jan 23, 2012
timon.gehr@gmx.ch
Jan 23, 2012
Walter Bright
Jan 24, 2012
timon.gehr@gmx.ch
Jan 24, 2012
timon.gehr@gmx.ch
Jan 24, 2012
Walter Bright
Jan 24, 2012
timon.gehr@gmx.ch
Mar 03, 2012
Kenji Hara
Jun 06, 2012
Kenji Hara
September 03, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3282

           Summary: The overload and override issue of const/immutable
                    member functions
           Product: D
           Version: 2.031
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: rayerd.wiz@gmail.com


import std.stdio;
class Base
{
    string f()
    {
        return "Base.f()";
    }
}
class Derived : Base
{
    string f()
    {
        return "Derived.f()";
    }
    string f() const // or immutable
    {
        return "Derived.f() const";
    }
}
void main()
{
    auto x = new Base;
    writeln(x.f());
    auto y = new Derived;
    writeln(y.f());
    auto z = new const(Derived); // or immutable
    writeln(z.f()); //object.Error: Access Violation
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 19, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3282



--- Comment #1 from Haruki Shigemori <rayerd.wiz@gmail.com> 2009-10-19 03:22:09 PDT ---
This problem occurs when "const" is "shared".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 22, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3282


Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario@gmx.de


--- Comment #2 from Rainer Schuetze <r.sagitario@gmx.de> 2010-01-22 00:37:37 PST ---
This kind of works now with changeset 344. But both "f()" and "f() const"
overload "f()" in the base class, and the last one wins. I think dmd should
either issue an error or add another entry to the vtbl for the non-exact but
covariant match.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 31, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3282



--- Comment #3 from Haruki Shigemori <rayerd.wiz@gmail.com> 2010-01-30 23:34:40 PST ---
This problem's characteristics changed at dmd2.040.

import std.stdio;
class Base
{
    string f()
    {
        return "Base.f()";
    }
}
class Derived : Base
{
    string f()
    {
        return "Derived.f()";
    }
    string f() immutable
    {
        return "Derived.f() immutable";
    }
    string f() shared
    {
        return "Derived.f() shared";
    }
}
void main()
{
    auto x = new Base;
    writeln(x.f());
    auto y = new Derived;
    writeln(y.f());
    auto z = new immutable(Derived);
        //main.d(15): Error: function main.Derived.f of type immutable string()
overrides but is not covariant with main.Base.f of type string()
    writeln(z.f());
    auto w = new shared(Derived);
        //main.d(19): Error: function main.Derived.f of type shared string()
overrides but is not covariant with main.Base.f of type string()
    writeln(w.f());
}

Are both errors correctly?
I expected that z.f() calls "Derived.f() immutable" and w.f() calls
"Derived.f() shared".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3282


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2012-01-23 01:28:50 PST ---
I believe the errors are correct.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3282


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |WORKSFORME


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3282


timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |timon.gehr@gmx.ch
         Resolution|WORKSFORME                  |


--- Comment #5 from timon.gehr@gmx.ch 2012-01-23 13:41:57 PST ---
I think it is a bug. The derived class introduces two additional overloads. The compiler claims that all three overloads override the same function.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3282


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #6 from Walter Bright <bugzilla@digitalmars.com> 2012-01-23 15:47:44 PST ---
(In reply to comment #5)
> I think it is a bug. The derived class introduces two additional overloads. The compiler claims that all three overloads override the same function.

The error messages are deliberate.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3282


timon.gehr@gmx.ch changed:

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


--- Comment #7 from timon.gehr@gmx.ch 2012-01-23 16:37:46 PST ---
If so, why is this code accepted?

class A{
    void f(int){}
}
class B: A{
    override void f(int){}
    void f(immutable int){}
    void f(shared int){}
}

What is the point of deliberately treating the hidden this pointer special regarding overloading?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3282



--- Comment #8 from timon.gehr@gmx.ch 2012-01-23 16:39:10 PST ---
Furthermore, this works, of course:

class B{
    void f(int){}
    void f(int)immutable{}
    void f(int)shared{}
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2