public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61966] New: [C++11] std::terminate called after throwing exception from destructor [g++] [4.8.2] [4.9.1]
@ 2014-07-30 15:42 formenel at gmail dot com
  2014-07-30 15:43 ` [Bug c++/61966] " formenel at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: formenel at gmail dot com @ 2014-07-30 15:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 61966
           Summary: [C++11] std::terminate called after throwing exception
                    from destructor [g++] [4.8.2] [4.9.1]
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: formenel at gmail dot com

Created attachment 33215
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33215&action=edit
ii file - 4.8.2

According to C++ standard 15.2.2 - It's allowed to throw exception from class
destructor. If exception from destructor thrown during stack unwinding
std::terminate is called, otherwise exception should be handled normally


Problem exists only with -std=c++11, version 4.6.0 behaves ok
Here is code which generates call to std::terminate though standard allows it:

class Exc : public std::exception {
public:
    virtual const char* what() const throw()
    { return "test exception"; }
};

class Test {
public:
    Test()
    { } 

    ~Test()
    {   
        throw Exc();
    }   
};


int main()
{
    try {
        {
            Test();
        }
    }   
    catch (Exc& exc)
    {   
        std::cout << exc.what() << std::endl;
    }   
}

Compile line:
g++ -v -save-temps -Wall -Wextra -std=c++11 exc-terminate.cc

-------------------------------- g++ 4.8.2 output ---------------

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.8 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap
--enable-plugin --with-system-zlib --disable-browser-plugin
--enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-std=c++11'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.8/cc1plus -E -quiet -v -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE exc-terminate.cc -mtune=generic -march=x86-64
-std=c++11 -Wall -Wextra -fpch-preprocess -fstack-protector -Wformat
-Wformat-security -o exc-terminate.ii
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/4.8"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.8
 /usr/include/x86_64-linux-gnu/c++/4.8
 /usr/include/c++/4.8/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-std=c++11'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.8/cc1plus -fpreprocessed exc-terminate.ii
-quiet -dumpbase exc-terminate.cc -mtune=generic -march=x86-64 -auxbase
exc-terminate -Wall -Wextra -std=c++11 -version -fstack-protector -Wformat
-Wformat-security -o exc-terminate.s
GNU C++ (Ubuntu 4.8.2-19ubuntu1) version 4.8.2 (x86_64-linux-gnu)
    compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p3,
MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (Ubuntu 4.8.2-19ubuntu1) version 4.8.2 (x86_64-linux-gnu)
    compiled by GNU C version 4.8.2, GMP version 5.1.3, MPFR version 3.1.2-p3,
MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 26a7c0bd346d04102f6aea776e0cccc5
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-std=c++11'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as -v --64 -o exc-terminate.o exc-terminate.s
GNU assembler version 2.24 (x86_64-linux-gnu) using BFD version (GNU Binutils
for Ubuntu) 2.24
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-std=c++11'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.8/collect2 --sysroot=/ --build-id
--eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker
/lib64/ld-linux-x86-64.so.2 -z relro
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o
-L/usr/lib/gcc/x86_64-linux-gnu/4.8
-L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu
-L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib -L/lib/x86_64-linux-gnu
-L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib
-L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. exc-terminate.o -lstdc++ -lm
-lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o


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

* [Bug c++/61966] [C++11] std::terminate called after throwing exception from destructor [g++] [4.8.2] [4.9.1]
  2014-07-30 15:42 [Bug c++/61966] New: [C++11] std::terminate called after throwing exception from destructor [g++] [4.8.2] [4.9.1] formenel at gmail dot com
@ 2014-07-30 15:43 ` formenel at gmail dot com
  2014-07-30 16:03 ` formenel at gmail dot com
  2014-07-30 16:10 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: formenel at gmail dot com @ 2014-07-30 15:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Sergey Murzin <formenel at gmail dot com> ---
Same problem exists in 4.9.1


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

* [Bug c++/61966] [C++11] std::terminate called after throwing exception from destructor [g++] [4.8.2] [4.9.1]
  2014-07-30 15:42 [Bug c++/61966] New: [C++11] std::terminate called after throwing exception from destructor [g++] [4.8.2] [4.9.1] formenel at gmail dot com
  2014-07-30 15:43 ` [Bug c++/61966] " formenel at gmail dot com
@ 2014-07-30 16:03 ` formenel at gmail dot com
  2014-07-30 16:10 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: formenel at gmail dot com @ 2014-07-30 16:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Sergey Murzin <formenel at gmail dot com> ---
Problem doesn't exist in 4.6.0 and 4.7.2


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

* [Bug c++/61966] [C++11] std::terminate called after throwing exception from destructor [g++] [4.8.2] [4.9.1]
  2014-07-30 15:42 [Bug c++/61966] New: [C++11] std::terminate called after throwing exception from destructor [g++] [4.8.2] [4.9.1] formenel at gmail dot com
  2014-07-30 15:43 ` [Bug c++/61966] " formenel at gmail dot com
  2014-07-30 16:03 ` formenel at gmail dot com
@ 2014-07-30 16:10 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2014-07-30 16:10 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Sergey Murzin from comment #0)
> Created attachment 33215 [details]
> ii file - 4.8.2
> 
> According to C++ standard 15.2.2 - It's allowed to throw exception from
> class destructor.

In C++11 destructors have noexcept(true) by default, so they're allowed to
throw, but it will call std::terminate.

If you want to throw from destructors they need to have noexcept(false)


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

end of thread, other threads:[~2014-07-30 16:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-30 15:42 [Bug c++/61966] New: [C++11] std::terminate called after throwing exception from destructor [g++] [4.8.2] [4.9.1] formenel at gmail dot com
2014-07-30 15:43 ` [Bug c++/61966] " formenel at gmail dot com
2014-07-30 16:03 ` formenel at gmail dot com
2014-07-30 16:10 ` redi 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).