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

             Bug #: 51295
           Summary: [C++11][noexcept] Wrong c'tor exception-specification
                    with non-trivial d'tor
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: daniel.krueg...@googlemail.com
                CC: ja...@gcc.gnu.org


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.

Reply via email to