Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 27, 2009 [Issue 3655] New: Virtual functions without bodies are not optimized away. | ||||
---|---|---|---|---|
| ||||
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 --- Comment #0 from Eldar Insafutdinov <e.insafutdinov@gmail.com> 2009-12-27 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: ------- |
December 27, 2009 [Issue 3655] Virtual functions without bodies are not optimized away. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Eldar Insafutdinov | http://d.puremagic.com/issues/show_bug.cgi?id=3655 --- Comment #1 from Eldar Insafutdinov <e.insafutdinov@gmail.com> 2009-12-27 04:13:25 PST --- (In reply to comment #0) > 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: ------- |
December 27, 2009 [Issue 3655] Virtual functions without bodies are not optimized away. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Eldar Insafutdinov | http://d.puremagic.com/issues/show_bug.cgi?id=3655 --- Comment #2 from Eldar Insafutdinov <e.insafutdinov@gmail.com> 2009-12-27 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: ------- |
December 29, 2009 [Issue 3655] Virtual functions without bodies are not optimized away. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Eldar Insafutdinov | 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 --- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2009-12-28 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: ------- |
Copyright © 1999-2021 by the D Language Foundation