www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2894] New: abstract classes sometimes allow non-abstract bodyless functions

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

           Summary: abstract classes sometimes allow non-abstract bodyless
                    functions
           Product: D
           Version: 1.043
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: kamm-removethis incasoftware.de


This compiles and links

abstract class C { void foo(); }
void main() {}

while this doesn't

interface I { void foo(); }
abstract class C : I { void foo(); }
void main() {}

with an undefined reference to `_D7abstfun1C3fooMFZv'.

Since methods in abstract classes may have bodies and being allowed to
implement a member function elsewhere than the class definition is a goal (see
resolution of bug 1289), the first case should also require a definition for
foo. This is also what I would expect from reading the spec on abstract
functions and classes.


-- 
Apr 25 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2894


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Keywords|wrong-code                  |link-failure, spec





That the first example links is understandable - because C.foo is never used,
the compiler doesn't create any references to it.

That the second example fails is semi-understandable - presumably the compiler
creates a vtbl for C's implementation of I, but the linker cannot resolve it
because no implementation of C.foo() has been linked in.  However, it does seem
that DMD could be better at DCE.

Less understandable is that this fails with the same error:
----------
abstract class C { void foo(); }
class D : C {}
void main() { }
----------

It was my understanding as well that a function in an abstract class is
automatically abstract if no body is given.  But it appears now that it's the
same as in a non-abstract - if the function isn't declared abstract, it
references an externally-defined function.  Still, the spec probably needs to
be clearer on the issue.


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




Commit pushed to
https://github.com/D-Programming-Language/d-programming-language.org

https://github.com/D-Programming-Language/d-programming-language.org/commit/341a8f7233d74c9313625290eff8af57af3c2d2a
fix Issue 2894 - abstract classes sometimes allow non-abstract bodyless
functions

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 23 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2894


Walter Bright <bugzilla digitalmars.com> changed:

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


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