This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/66223] New: Diagnostic of pure virtual function call broken, including __cxa_pure_virtual
- From: "d.frey at gmx dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 20 May 2015 15:49:26 +0000
- Subject: [Bug c++/66223] New: Diagnostic of pure virtual function call broken, including __cxa_pure_virtual
- Auto-submitted: auto-generated
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.