www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2196] New: Link errors with an abstract class's method implementing an interface

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2196

           Summary: Link errors with an abstract class's method implementing
                    an interface
           Product: D
           Version: 1.031
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: link-failure, spec
          Severity: minor
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: diggory.hardy gmail.com


The following code generates an error at link time:

interface A
{
    void foo ();
}

abstract class B : A
{
    void foo ();
}

void main() {}


The error:
abstract.o: In function `_TMP0':
abstract.d:(.text+0x4): undefined reference to `_D8abstract1B3fooMFZv'
collect2: ld returned 1 exit status


Marking foo in B as abstract avoids the problem. The documentation isn't at all
clear on whether this should be the case.

Tried with dmd 1.031 and 1.027, and gcc (Debian 4.3.1-2) 4.3.1.


-- 
Jul 05 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2196






I'm not sure if it is a bug, this is a correct behaviour to me.

In this code:
abstract class B : A {
    void foo ();
}

you define a method foo() and should provide a function body somewhere. Merely
marking class abstract says that you can't instantiate it, but you can any
other class that subclasses from it, unless it is abstract, too. If you mark
you method as abstract it means that there is no body, child class should
provide an implementation.

Interface methods are implicitly abstract.


-- 
Jul 06 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2196


gide nwawudu.com changed:

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






 I'm not sure if it is a bug, this is a correct behaviour to me.
 If you mark your method as abstract it means that there is no body, 
 child class should provide an implementation.
The following compiles correctly, the original code should not link. interface A { void foo (); } abstract class B : A { abstract void foo (); } void main() {} --
Apr 23 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2196


diggory.hardy gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |CLOSED





Agreed.

I think what I was unsure on is why the linker wanted the definitions of an
abstract class that wasn't (attempted to be) used. But of course having to
explicitly mark such functions as abstract does make it clear whether or not
the function was intended to be defined in that class.


-- 
Apr 23 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2196


Andrei Alexandrescu <andrei erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|CLOSED                      |RESOLVED
                 CC|                            |andrei erdani.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2013