public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58859] New: throwing exceptions in destructors causes std::terminate called too early.
@ 2013-10-24  5:47 meng at g dot clemson.edu
  2013-10-24  5:50 ` [Bug c++/58859] throwing exceptions in destructors causes std::terminate called unnecessarily meng at g dot clemson.edu
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: meng at g dot clemson.edu @ 2013-10-24  5:47 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58859

            Bug ID: 58859
           Summary: throwing exceptions in destructors causes
                    std::terminate called too early.
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: meng at g dot clemson.edu

the following program does not execute (2) for g++-4.8.[01] -std=c++11 and I
think this is a bug. I tested the program on g++-4.[67].[01] with or without
c++11 enabled, and g++-4.8.0 with c++11 flag, and in VS 2010, in all these
cases, (2) was executed and the program finished without a call to
std::terminate. My understanding is that the throw expression happens before
stack unwinding and that there is a matching handler, therefore, std::terminate
should not be called.

----------------------- BEGIN -----------------------
#include <iostream>

struct test_t
{
 test_t () { std::cout << " test_t @ " << this << std::endl; }
~test_t () { std::cout << "~test_t @ " << this << std::endl; throw 0; }
};

int main ()
{
 try
 {
  test_t const t; // (1)
 }
 catch (...)
 {
  std::cout << __LINE__ << std::endl; // (2)
 }
}
-----------------------  END  -----------------------


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

* [Bug c++/58859] throwing exceptions in destructors causes std::terminate called unnecessarily.
  2013-10-24  5:47 [Bug c++/58859] New: throwing exceptions in destructors causes std::terminate called too early meng at g dot clemson.edu
@ 2013-10-24  5:50 ` meng at g dot clemson.edu
  2013-10-24  6:05 ` glisse at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: meng at g dot clemson.edu @ 2013-10-24  5:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58859

--- Comment #1 from meng at g dot clemson.edu ---
made a typo just now.
"and g++-4.8.0 with c++11 flag, "
should read
"and g++-4.8.0 without c++11 flag, "

i.e., the problem only happens when c++11 is enabled with g++-4.8.0.


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

* [Bug c++/58859] throwing exceptions in destructors causes std::terminate called unnecessarily.
  2013-10-24  5:47 [Bug c++/58859] New: throwing exceptions in destructors causes std::terminate called too early meng at g dot clemson.edu
  2013-10-24  5:50 ` [Bug c++/58859] throwing exceptions in destructors causes std::terminate called unnecessarily meng at g dot clemson.edu
@ 2013-10-24  6:05 ` glisse at gcc dot gnu.org
  2013-10-24  6:34 ` meng at g dot clemson.edu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-24  6:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58859

--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> ---
Try adding noexcept(false) on the destructor?


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

* [Bug c++/58859] throwing exceptions in destructors causes std::terminate called unnecessarily.
  2013-10-24  5:47 [Bug c++/58859] New: throwing exceptions in destructors causes std::terminate called too early meng at g dot clemson.edu
  2013-10-24  5:50 ` [Bug c++/58859] throwing exceptions in destructors causes std::terminate called unnecessarily meng at g dot clemson.edu
  2013-10-24  6:05 ` glisse at gcc dot gnu.org
@ 2013-10-24  6:34 ` meng at g dot clemson.edu
  2013-10-24  6:42 ` meng at g dot clemson.edu
  2013-10-24  9:16 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: meng at g dot clemson.edu @ 2013-10-24  6:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58859

--- Comment #3 from meng at g dot clemson.edu ---
(In reply to Marc Glisse from comment #2)
> Try adding noexcept(false) on the destructor?

that works. Thanks.
but this causes another question.

c++11 15.4/12 states
"A function with no exception-specification or with an exception-specification
of the form noexcept(constant-expression) where the constant-expression yields
false allows all exceptions."

my understanding is that having no exception-specification is equivalent to say
noexcept(false), i.e., functions are considered to throw exceptions by default
unless specified otherwise. I think this is also supported by 5.3.7/3 bullet 1.

interestingly, though, the following failed on 4.8.[01] and succeeded on
earlier versions of g++ that I have.

 static_assert(noexcept(std::declval<test_t>().~test_t())==false,"");

did I misunderstand something?


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

* [Bug c++/58859] throwing exceptions in destructors causes std::terminate called unnecessarily.
  2013-10-24  5:47 [Bug c++/58859] New: throwing exceptions in destructors causes std::terminate called too early meng at g dot clemson.edu
                   ` (2 preceding siblings ...)
  2013-10-24  6:34 ` meng at g dot clemson.edu
@ 2013-10-24  6:42 ` meng at g dot clemson.edu
  2013-10-24  9:16 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: meng at g dot clemson.edu @ 2013-10-24  6:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58859

--- Comment #4 from meng at g dot clemson.edu ---
ok, I think I missed 15.4/4 and 12.4/3, which means the dtor in my example
should allow no exceptions, i.e., noexcept(true). Thanks again.


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

* [Bug c++/58859] throwing exceptions in destructors causes std::terminate called unnecessarily.
  2013-10-24  5:47 [Bug c++/58859] New: throwing exceptions in destructors causes std::terminate called too early meng at g dot clemson.edu
                   ` (3 preceding siblings ...)
  2013-10-24  6:42 ` meng at g dot clemson.edu
@ 2013-10-24  9:16 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-24  9:16 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58859

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|meng at g dot clemson.edu          |
         Resolution|---                         |INVALID

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Closing.


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

end of thread, other threads:[~2013-10-24  9:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-24  5:47 [Bug c++/58859] New: throwing exceptions in destructors causes std::terminate called too early meng at g dot clemson.edu
2013-10-24  5:50 ` [Bug c++/58859] throwing exceptions in destructors causes std::terminate called unnecessarily meng at g dot clemson.edu
2013-10-24  6:05 ` glisse at gcc dot gnu.org
2013-10-24  6:34 ` meng at g dot clemson.edu
2013-10-24  6:42 ` meng at g dot clemson.edu
2013-10-24  9:16 ` paolo.carlini at oracle dot com

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).