This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/69777] New: Give a warning when virtual function is devirtualized into a __cxa_pure_virtual call


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69777

            Bug ID: 69777
           Summary: Give a warning when virtual function is devirtualized
                    into a __cxa_pure_virtual call
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vz-gcc at zeitlins dot org
  Target Milestone: ---

For the reasons of compatibility with old compilers which don't define some
Windows COM interfaces in their headers, we define these interfaces ourselves,
e.g. here:
https://github.com/wxWidgets/wxWidgets/blob/WX_3_0_2/src/msw/textentry.cpp#L92

It seems that g++ 4.9.1 is smart enough to deduce that no classes deriving from
a class declared in an anonymous namespace can exist outside of the current
translation unit and so all IAutoCompleteDropDown pointers can only point to
objects of the base IAutoCompleteDropDown type itself and then it proceeds with
devirtualizing the calls to its methods to just directly call
__cxa_pure_virtual() (i.e. instead of the usual indirect call I just see "call
__cxa_pure_virtual" in the x86 disassembly).

This is technically correct, of course, and rather impressive, but as the
generated code will always crash during run-time, couldn't g++ give a warning
when devirtualizing a function into a pure virtual call? This would have helped
me a lot when tracking down this crash (which was not totally obvious because
the stack was shifted on entry into __cxa_pure_virtual() as the calling code
temporarily changed esp register value).

I have a small (but still ~50 lines of code) example that can be used to
reproduce this behaviour, please let me know if you'd like me to attach it.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]