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

             Bug #: 51438
           Summary: std::exception and derived classes are not compatible
                    with std::nested_exception and C++11 in general
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: cu...@cubbi.org


As implemented in gcc-4.7.0_alpha20111126, struct _Nested_exception has an
implicit destructor, while std::exception and all <stdexcept> exception classes
have explicit destructors with "throw()".

Because of this, it's impossible to use std::throw_with_nested with any
exception derived from std::exception:

#include <exception>
#include <stdexcept>
int main()
{
    try {
        throw 2;
    } catch(int) {
        std::throw_with_nested(std::runtime_error("test"));
    }
}

gives compilation error:

In file included from
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20111126/include/g++-v4/exception:155:0,
                 from test.cc:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20111126/include/g++-v4/bits/nested_exception.h:
In instantiation of ‘struct std::_Nested_exception<std::runtime_error>’:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20111126/include/g++-v4/bits/nested_exception.h:126:60:
  required from ‘void std::__throw_with_nested(_Ex&&, ...) [with _Ex =
std::runtime_error]’
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20111126/include/g++-v4/bits/nested_exception.h:140:7:
  required from ‘void std::throw_with_nested(_Ex) [with _Ex =
std::runtime_error]’
test.cc:8:58:   required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20111126/include/g++-v4/bits/nested_exception.h:78:12:
error: looser throw specifier for ‘virtual
std::_Nested_exception<std::runtime_error>::~_Nested_exception()’
In file included from test.cc:2:0:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0-alpha20111126/include/g++-v4/stdexcept:122:13:
error:   overriding ‘virtual std::runtime_error::~runtime_error() throw ()’



suggested fix: remove "throw()" in <exception> and <stdexcept> in C++11 mode.
The C++11 version of class exception should have "virtual ~exception();" and
other member functions should be noexcept (per §18.8.1) and the <stdexcept>
classes should have implicit dtors (per §19.2).

Reply via email to