Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// test bad_exception
|
||||
|
||||
#include <exception>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert((std::is_base_of<std::exception, std::bad_exception>::value),
|
||||
"std::is_base_of<std::exception, std::bad_exception>::value");
|
||||
static_assert(std::is_polymorphic<std::bad_exception>::value,
|
||||
"std::is_polymorphic<std::bad_exception>::value");
|
||||
std::bad_exception b;
|
||||
std::bad_exception b2 = b;
|
||||
b2 = b;
|
||||
const char* w = b2.what();
|
||||
assert(w);
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// nested_exception& operator=(const nested_exception&) throw() = default;
|
||||
|
||||
#include <exception>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
int data_;
|
||||
public:
|
||||
explicit A(int data) : data_(data) {}
|
||||
|
||||
friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::nested_exception e0;
|
||||
std::nested_exception e;
|
||||
e = e0;
|
||||
assert(e.nested_ptr() == nullptr);
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
throw A(2);
|
||||
assert(false);
|
||||
}
|
||||
catch (const A&)
|
||||
{
|
||||
std::nested_exception e0;
|
||||
std::nested_exception e;
|
||||
e = e0;
|
||||
assert(e.nested_ptr() != nullptr);
|
||||
try
|
||||
{
|
||||
rethrow_exception(e.nested_ptr());
|
||||
assert(false);
|
||||
}
|
||||
catch (const A& a)
|
||||
{
|
||||
assert(a == A(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// nested_exception(const nested_exception&) throw() = default;
|
||||
|
||||
#include <exception>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
int data_;
|
||||
public:
|
||||
explicit A(int data) : data_(data) {}
|
||||
|
||||
friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::nested_exception e0;
|
||||
std::nested_exception e = e0;
|
||||
assert(e.nested_ptr() == nullptr);
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
throw A(2);
|
||||
assert(false);
|
||||
}
|
||||
catch (const A&)
|
||||
{
|
||||
std::nested_exception e0;
|
||||
std::nested_exception e = e0;
|
||||
assert(e.nested_ptr() != nullptr);
|
||||
try
|
||||
{
|
||||
rethrow_exception(e.nested_ptr());
|
||||
assert(false);
|
||||
}
|
||||
catch (const A& a)
|
||||
{
|
||||
assert(a == A(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// nested_exception() throw();
|
||||
|
||||
#include <exception>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
int data_;
|
||||
public:
|
||||
explicit A(int data) : data_(data) {}
|
||||
|
||||
friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::nested_exception e;
|
||||
assert(e.nested_ptr() == nullptr);
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
throw A(2);
|
||||
assert(false);
|
||||
}
|
||||
catch (const A&)
|
||||
{
|
||||
std::nested_exception e;
|
||||
assert(e.nested_ptr() != nullptr);
|
||||
try
|
||||
{
|
||||
rethrow_exception(e.nested_ptr());
|
||||
assert(false);
|
||||
}
|
||||
catch (const A& a)
|
||||
{
|
||||
assert(a == A(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,89 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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;
|
||||
|
||||
// void rethrow_nested [[noreturn]] () const;
|
||||
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
int data_;
|
||||
public:
|
||||
explicit A(int data) : data_(data) {}
|
||||
|
||||
friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
|
||||
};
|
||||
|
||||
void go_quietly()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
try
|
||||
{
|
||||
throw A(2);
|
||||
assert(false);
|
||||
}
|
||||
catch (const A&)
|
||||
{
|
||||
const std::nested_exception e;
|
||||
assert(e.nested_ptr() != nullptr);
|
||||
try
|
||||
{
|
||||
e.rethrow_nested();
|
||||
assert(false);
|
||||
}
|
||||
catch (const A& a)
|
||||
{
|
||||
assert(a == A(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
std::set_terminate(go_quietly);
|
||||
const std::nested_exception e;
|
||||
e.rethrow_nested();
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,103 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 T> void throw_with_nested [[noreturn]] (T&& t);
|
||||
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
int data_;
|
||||
public:
|
||||
explicit A(int data) : data_(data) {}
|
||||
|
||||
friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
|
||||
};
|
||||
|
||||
class B
|
||||
: public std::nested_exception
|
||||
{
|
||||
int data_;
|
||||
public:
|
||||
explicit B(int data) : data_(data) {}
|
||||
|
||||
friend bool operator==(const B& x, const B& y) {return x.data_ == y.data_;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
try
|
||||
{
|
||||
A a(3);
|
||||
std::throw_with_nested(a);
|
||||
assert(false);
|
||||
}
|
||||
catch (const A& a)
|
||||
{
|
||||
assert(a == A(3));
|
||||
}
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
A a(4);
|
||||
std::throw_with_nested(a);
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::nested_exception& e)
|
||||
{
|
||||
assert(e.nested_ptr() == nullptr);
|
||||
}
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
B b(5);
|
||||
std::throw_with_nested(b);
|
||||
assert(false);
|
||||
}
|
||||
catch (const B& b)
|
||||
{
|
||||
assert(b == B(5));
|
||||
}
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
B b(6);
|
||||
std::throw_with_nested(b);
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::nested_exception& e)
|
||||
{
|
||||
assert(e.nested_ptr() == nullptr);
|
||||
const B& b = dynamic_cast<const B&>(e);
|
||||
assert(b == B(6));
|
||||
}
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
int i = 7;
|
||||
std::throw_with_nested(i);
|
||||
assert(false);
|
||||
}
|
||||
catch (int i)
|
||||
{
|
||||
assert(i == 7);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// test get_terminate
|
||||
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
void f1() {}
|
||||
void f2() {}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
assert(std::get_terminate() == f1);
|
||||
std::set_terminate(f2);
|
||||
assert(std::get_terminate() == f2);
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// test set_terminate
|
||||
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
void f1() {}
|
||||
void f2() {}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
assert(std::set_terminate(f2) == f1);
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// test terminate_handler
|
||||
|
||||
#include <exception>
|
||||
|
||||
void f() {}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::terminate_handler p = f;
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// test terminate
|
||||
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
void f1()
|
||||
{
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(f1);
|
||||
std::terminate();
|
||||
assert(false);
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// test exception
|
||||
|
||||
#include <exception>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(std::is_polymorphic<std::exception>::value,
|
||||
"std::is_polymorphic<std::exception>::value");
|
||||
std::exception b;
|
||||
std::exception b2 = b;
|
||||
b2 = b;
|
||||
const char* w = b2.what();
|
||||
assert(w);
|
||||
}
|
@@ -0,0 +1,269 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// exception_ptr current_exception();
|
||||
|
||||
#include <exception>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int constructed;
|
||||
|
||||
A() {++constructed;}
|
||||
~A() {--constructed;}
|
||||
A(const A&) {++constructed;}
|
||||
};
|
||||
|
||||
int A::constructed = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::exception_ptr p = std::current_exception();
|
||||
assert(p == nullptr);
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 0);
|
||||
throw A();
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
{
|
||||
std::exception_ptr p2;
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 0);
|
||||
throw A();
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::exception_ptr p = std::current_exception();
|
||||
assert(A::constructed == 1);
|
||||
assert(p != nullptr);
|
||||
p2 = std::current_exception();
|
||||
assert(A::constructed == 1);
|
||||
assert(p == p2);
|
||||
}
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
{
|
||||
std::exception_ptr p2;
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 0);
|
||||
throw A();
|
||||
assert(false);
|
||||
}
|
||||
catch (A& a)
|
||||
{
|
||||
std::exception_ptr p = std::current_exception();
|
||||
assert(A::constructed == 1);
|
||||
assert(p != nullptr);
|
||||
p2 = std::current_exception();
|
||||
assert(A::constructed == 1);
|
||||
assert(p == p2);
|
||||
}
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
{
|
||||
std::exception_ptr p2;
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 0);
|
||||
throw A();
|
||||
assert(false);
|
||||
}
|
||||
catch (A a)
|
||||
{
|
||||
std::exception_ptr p = std::current_exception();
|
||||
assert(A::constructed == 2);
|
||||
assert(p != nullptr);
|
||||
p2 = std::current_exception();
|
||||
assert(A::constructed == 2);
|
||||
assert(p == p2);
|
||||
}
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
{
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 0);
|
||||
throw A();
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
throw;
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
{
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 0);
|
||||
throw A();
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
try
|
||||
{
|
||||
std::exception_ptr p = std::current_exception();
|
||||
assert(A::constructed == 1);
|
||||
assert(p != nullptr);
|
||||
throw;
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
{
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 0);
|
||||
throw A();
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
throw;
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::exception_ptr p = std::current_exception();
|
||||
assert(A::constructed == 1);
|
||||
assert(p != nullptr);
|
||||
}
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
{
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 0);
|
||||
throw A();
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
throw;
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
std::exception_ptr p = std::current_exception();
|
||||
assert(A::constructed == 1);
|
||||
assert(p != nullptr);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
{
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 0);
|
||||
throw A();
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
throw;
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
std::exception_ptr p = std::current_exception();
|
||||
assert(A::constructed == 0);
|
||||
assert(p == nullptr);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
{
|
||||
std::exception_ptr p;
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 0);
|
||||
throw A();
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
try
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
throw;
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
p = std::current_exception();
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 1);
|
||||
assert(p != nullptr);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// typedef unspecified exception_ptr;
|
||||
|
||||
// exception_ptr shall satisfy the requirements of NullablePointer.
|
||||
|
||||
#include <exception>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::exception_ptr p;
|
||||
assert(p == nullptr);
|
||||
std::exception_ptr p2 = p;
|
||||
assert(nullptr == p);
|
||||
assert(!p);
|
||||
assert(p2 == p);
|
||||
p2 = p;
|
||||
assert(p2 == p);
|
||||
assert(p2 == nullptr);
|
||||
std::exception_ptr p3 = nullptr;
|
||||
assert(p3 == nullptr);
|
||||
p3 = nullptr;
|
||||
assert(p3 == nullptr);
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// template<class E> exception_ptr make_exception_ptr(E e);
|
||||
|
||||
#include <exception>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int constructed;
|
||||
int data_;
|
||||
|
||||
A(int data = 0) : data_(data) {++constructed;}
|
||||
~A() {--constructed;}
|
||||
A(const A& a) : data_(a.data_) {++constructed;}
|
||||
};
|
||||
|
||||
int A::constructed = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::exception_ptr p = std::make_exception_ptr(A(5));
|
||||
try
|
||||
{
|
||||
std::rethrow_exception(p);
|
||||
assert(false);
|
||||
}
|
||||
catch (const A& a)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
assert(p != nullptr);
|
||||
p = nullptr;
|
||||
assert(p == nullptr);
|
||||
assert(a.data_ == 5);
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
// void rethrow_exception [[noreturn]] (exception_ptr p);
|
||||
|
||||
#include <exception>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int constructed;
|
||||
int data_;
|
||||
|
||||
A(int data = 0) : data_(data) {++constructed;}
|
||||
~A() {--constructed;}
|
||||
A(const A& a) : data_(a.data_) {++constructed;}
|
||||
};
|
||||
|
||||
int A::constructed = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::exception_ptr p;
|
||||
try
|
||||
{
|
||||
throw A(3);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
p = std::current_exception();
|
||||
}
|
||||
try
|
||||
{
|
||||
std::rethrow_exception(p);
|
||||
assert(false);
|
||||
}
|
||||
catch (const A& a)
|
||||
{
|
||||
assert(A::constructed == 1);
|
||||
assert(p != nullptr);
|
||||
p = nullptr;
|
||||
assert(p == nullptr);
|
||||
assert(a.data_ == 3);
|
||||
assert(A::constructed == 1);
|
||||
}
|
||||
assert(A::constructed == 0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// test uncaught_exception
|
||||
|
||||
#include <exception>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
~A()
|
||||
{
|
||||
assert(std::uncaught_exception());
|
||||
}
|
||||
};
|
||||
|
||||
struct B
|
||||
{
|
||||
B()
|
||||
{
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#475
|
||||
assert(!std::uncaught_exception());
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
A a;
|
||||
assert(!std::uncaught_exception());
|
||||
throw B();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(!std::uncaught_exception());
|
||||
}
|
||||
assert(!std::uncaught_exception());
|
||||
}
|
20
test/std/language.support/support.exception/version.pass.cpp
Normal file
20
test/std/language.support/support.exception/version.pass.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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>
|
||||
|
||||
#include <exception>
|
||||
|
||||
#ifndef _LIBCPP_VERSION
|
||||
#error _LIBCPP_VERSION not defined
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user