public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66223] New: Diagnostic of pure virtual function call broken, including __cxa_pure_virtual
@ 2015-05-20 15:49 d.frey at gmx dot de
  2015-05-21  9:08 ` [Bug c++/66223] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: d.frey at gmx dot de @ 2015-05-20 15:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66223
           Summary: Diagnostic of pure virtual function call broken,
                    including __cxa_pure_virtual
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: d.frey at gmx dot de
  Target Milestone: ---

Consider this small and certainly broken program:

    struct B {
        B* self;
        B() : self( this ) { self->f(); }
        virtual void f() = 0;
    };

    struct D : B
    {
        void f() {}
    };

    int main()
    {
        D d;
    }

The ctor of B calls (indirectly) the pure virtual function f(), but the vtbl is
still from B, not D (yet). Hence the program crashes. With GCC 4.9, I got:

    > ./a.out
    pure virtual method called
    terminate called without an active exception
    Aborted (core dumped)
    >

Which is a good hint and I got a core dump. Fine so far. With GCC 5.1, I get
this:

    > ./a.out
    Segmentation fault (core dumped)
    >

Which is certainly less helpful.

What is actually a lot worse is that even __cxa_pure_virtual is severly broken.
I used to have my own __cxa_pure_virtual method to provide more output
including a backtrace, something like this was my output for GCC 4.9:

    > ./a.out
    ### EMERGENCY ###
    pure virtual function called
    ### BACKTRACE ###
   
build/release/test/emergency/pure_virtual_XFAIL(coin::core::output::backtrace()+0x23)
[0x4034a3]
    build/release/test/emergency/pure_virtual_XFAIL(__cxa_pure_virtual+0x47)
[0x4031f7]
    build/release/test/emergency/pure_virtual_XFAIL() [0x402a09]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7ff9dd52dec5]
    build/release/test/emergency/pure_virtual_XFAIL() [0x402b14]
    ### ABORTING ###
    Aborted (core dumped)
    >

After the backtrace was printed to stdout, a core dump was written. With GCC
5.1, all I get is:

    > ./a.out
    >

where at least the result code is not 0 (it's 128 if it helps). But no message
and no core dump.

Further experiments have shown that GCC 5.1 actually calls the terminate
handler (which I also registered via std::set_terminate). This handler prints a
backtrace and some other information when called on other errors, but for a
pure virtual call it seems to be unable to even call a simple write() to
stdout.

Please let me know if you need further help to debug and fix this problem. I
realize it's "just" a diagnostic in case of calling an unimplemented pure
virtual method which should not be done in the first place, but I think the
current situation is really hurting people when there is absolutely no message
and no core dump and the process just returns with a non-zero exit code.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-10-16  8:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-20 15:49 [Bug c++/66223] New: Diagnostic of pure virtual function call broken, including __cxa_pure_virtual d.frey at gmx dot de
2015-05-21  9:08 ` [Bug c++/66223] " redi at gcc dot gnu.org
2015-05-21 20:30 ` d.frey at gmx dot de
2015-05-22  9:42 ` [Bug ipa/66223] [5/6 Regression] " redi at gcc dot gnu.org
2015-10-16  8:27 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).