Sean Hunt 2d81f3d1f3 Give A an explicitly non-throwing destructor so that B's destructor is
itself non-throwing.  Since nested_exception's destructor is
non-throwing, if B's destructor is not, this causes an error in C++03
mode due to the overriding function having a more lax specification.
This did not occur in C++0x mode as A's destructor was implicitly
non-throwing.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@135400 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-18 17:07:53 +00:00

90 lines
1.7 KiB
C++

//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <exception>
// class nested_exception;
// template <class E> void rethrow_if_nested(const E& e);
#include <exception>
#include <cstdlib>
#include <cassert>
class A
{
int data_;
public:
explicit A(int data) : data_(data) {}
virtual ~A() _NOEXCEPT {}
friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
};
class B
: public std::nested_exception,
public A
{
public:
explicit B(int data) : A(data) {}
B(const B& b) : A(b) {}
};
int main()
{
{
try
{
A a(3);
std::rethrow_if_nested(a);
assert(true);
}
catch (...)
{
assert(false);
}
}
{
try
{
throw B(5);
}
catch (const B& b)
{
try
{
throw b;
}
catch (const A& a)
{
try
{
std::rethrow_if_nested(a);
assert(false);
}
catch (const B& b)
{
assert(b == B(5));
}
}
}
}
{
try
{
std::rethrow_if_nested(1);
assert(true);
}
catch (...)
{
assert(false);
}
}
}