www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3655] New: Virtual functions without bodies are not optimized away.

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

           Summary: Virtual functions without bodies are not optimized
                    away.
           Product: D
           Version: 2.035
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: e.insafutdinov gmail.com



04:12:27 PST ---
This is compiled fine, as final method without a body is optimized away:

class Boo
{
    final void foo();
}

However this does not:

class Boo
{
    void foo();
}

linker fails with:

main.o:(.rodata+0x194): undefined reference to `_D4main3Boo3fooMFZv'

This might be because function is put into vtable. Is it easy to fix?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 27 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3655




04:13:25 PST ---

 This is compiled fine, as final method without a body is optimized away:
 
 class Boo
 {
     final void foo();
 }
 
Of course it is optimized away if it is not used. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 27 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3655




05:03:55 PST ---
Ok, actually I am wrong here, final methods are not optimized away - they just
don't exist. And if nobody uses them - you are safe. But the similar behavior
should be present for virtual functions as well I believe - virtual function
without a body should not be present in vtable.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 27 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3655


Walter Bright <bugzilla digitalmars.com> changed:

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



21:14:32 PST ---
The compiler is working as designed.

The final function is not virtual, so it is never needed in the vtbl[]. Hence,
there is no undefined reference to it in the vtbl[].

The non-final function is virtual, and so a reference to it is put into the
vtbl[]. The function's implementation must exist somewhere, and if it did, the
linker would put a reference to the implementation in the vtbl[]. This feature
allows one to have an implementation that is hidden from the user of the class.

If you truly do not want to implement the function, declare it as 'abstract'.
Then, a NULL is put in the corresponding place in the vtbl[].

Not a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 28 2009