public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97720] New: Sometimes std::current_exception does not work properly in the terminate handler
@ 2020-11-04 20:54 m101010a at gmail dot com
  2020-11-04 21:20 ` [Bug c++/97720] " redi at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: m101010a at gmail dot com @ 2020-11-04 20:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97720
           Summary: Sometimes std::current_exception does not work
                    properly in the terminate handler
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m101010a at gmail dot com
  Target Milestone: ---

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id
--enable-lto --enable-multilib --enable-plugin --enable-shared
--enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-libunwind-exceptions --disable-werror
gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC) 
$ cat x.cpp
#include <iostream>

struct has_destructor {
        ~has_destructor();
};

void do_nothing();

inline int throwing_function() {
#ifdef DESTRUCTOR
        has_destructor hd;
#endif
        throw "";
}

class C {
public:
        C() noexcept;
        ~C();
};

C::C() noexcept {throwing_function();}
inline C::~C() { do_nothing(); }

static void term_handler() {
        const char *f = "Died without exception\n";
        auto e = std::current_exception();
        if (e)
                f = "Died with exception\n";
        std::cout << f << std::flush;
        quick_exit(0);
}

int main() {
        std::set_terminate(&term_handler);
        C{};
}
$ cat y.cpp
struct has_destructor {
        ~has_destructor();
};

void do_nothing();

has_destructor::~has_destructor() = default;
void do_nothing() {}
$ g++ x.cpp y.cpp -O1
$ ./a.out
Died with exception
$ g++ -DDESTRUCTOR x.cpp y.cpp -O1
$ ./a.out
Died without exception
$ 

This bug is very sensitive to small changes.  For example, it will correctly
get the exception_ptr when compiling with -O0 or -O2, or if C's constructor is
inline, or if C's destructor is not inline.  This is probably the underlying
cause of bug 97339.

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

end of thread, other threads:[~2024-05-07  7:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-04 20:54 [Bug c++/97720] New: Sometimes std::current_exception does not work properly in the terminate handler m101010a at gmail dot com
2020-11-04 21:20 ` [Bug c++/97720] " redi at gcc dot gnu.org
2020-11-05  2:02 ` m101010a at gmail dot com
2022-12-16 16:52 ` m101010a at gmail dot com
2023-05-22 21:34 ` [Bug c++/97720] throw in try in noexcept fn calls terminate without handling the exception jason at gcc dot gnu.org
2023-05-23  3:52 ` jason at gcc dot gnu.org
2023-05-23 17:20 ` m101010a at gmail dot com
2023-06-04  1:49 ` cvs-commit at gcc dot gnu.org
2023-06-04  2:08 ` jason at gcc dot gnu.org
2023-06-04  2:11 ` jason at gcc dot gnu.org
2024-05-07  7:39 ` 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).