Bug 51295 - [C++11][noexcept] Wrong c'tor exception-specification with non-trivial d'tor
Summary: [C++11][noexcept] Wrong c'tor exception-specification with non-trivial d'tor
Status: RESOLVED DUPLICATE of bug 50043
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: rejects-valid
Depends on:
Reported: 2011-11-24 15:00 UTC by Daniel Krügler
Modified: 2012-04-12 00:10 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Krügler 2011-11-24 15:00:21 UTC
I became aware of the following problem, when attempting to create something like boost::optional with all the C++11 bells and whistles.

gcc 4.7.0 20111119 (experimental) in C++11 mode with -Wall rejects the following code:

struct B {
  ~B() {}

static_assert(noexcept(B{}), "Error"); // Line 5

struct B2 {
  B2() noexcept {}
  ~B2() {}

static_assert(noexcept(B2{}), "Error"); // Line 12

struct D : B2 {
  D() noexcept = default; // Line 15

main.cpp|5|error: static assertion failed: "Error"|
main.cpp|12|error: static assertion failed: "Error"|
main.cpp|15|error: function 'D::D()' defaulted on its first declaration with an exception-specification that differs from the implicit declaration 'D::D()'

It seems that in some situations the compiler-deduced exception-specification of special members gives incorrect values not following FDIS rules. The root of the problem seems to be located when there exist user-provided destructors without exception-specification, even though these should behave as if they where declared as noexcept(true). In addition to that such destructors can influence the deduced exception-specification of constructors, as shown for type D.

A current workaround is to mark the destructors with noexcept as well. None the less this is a rather huge problem, because due to the popular existence of destructors without exception-specification this can lead to large number of failures in test cases.
Comment 1 Paolo Carlini 2011-12-09 16:03:29 UTC
*** Bug 51452 has been marked as a duplicate of this bug. ***
Comment 2 Jonathan Wakely 2012-01-12 16:19:04 UTC
is this just a dup of PR 50043 ?
Comment 3 Paolo Carlini 2012-04-12 00:10:26 UTC
Indeed duplicate.

*** This bug has been marked as a duplicate of bug 50043 ***