diff options
Diffstat (limited to 'libcxx/test/language.support/support.exception')
16 files changed, 676 insertions, 0 deletions
diff --git a/libcxx/test/language.support/support.exception/exception.terminate/nothing_to_do.pass.cpp b/libcxx/test/language.support/support.exception/exception.terminate/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..fa4d462f18d --- /dev/null +++ b/libcxx/test/language.support/support.exception/exception.terminate/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/language.support/support.exception/exception.terminate/set.terminate/set_terminate.pass.cpp b/libcxx/test/language.support/support.exception/exception.terminate/set.terminate/set_terminate.pass.cpp new file mode 100644 index 00000000000..21de6f285c0 --- /dev/null +++ b/libcxx/test/language.support/support.exception/exception.terminate/set.terminate/set_terminate.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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); +} diff --git a/libcxx/test/language.support/support.exception/exception.terminate/terminate.handler/terminate_handler.pass.cpp b/libcxx/test/language.support/support.exception/exception.terminate/terminate.handler/terminate_handler.pass.cpp new file mode 100644 index 00000000000..0a3a4573319 --- /dev/null +++ b/libcxx/test/language.support/support.exception/exception.terminate/terminate.handler/terminate_handler.pass.cpp @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test terminate_handler + +#include <exception> + +void f() {} + +int main() +{ + std::terminate_handler p = f; +} diff --git a/libcxx/test/language.support/support.exception/exception.terminate/terminate/terminate.pass.cpp b/libcxx/test/language.support/support.exception/exception.terminate/terminate/terminate.pass.cpp new file mode 100644 index 00000000000..b34051d9ed6 --- /dev/null +++ b/libcxx/test/language.support/support.exception/exception.terminate/terminate/terminate.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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); +} diff --git a/libcxx/test/language.support/support.exception/exception.unexpected/bad.exception/bad_exception.pass.cpp b/libcxx/test/language.support/support.exception/exception.unexpected/bad.exception/bad_exception.pass.cpp new file mode 100644 index 00000000000..9f32dac7e75 --- /dev/null +++ b/libcxx/test/language.support/support.exception/exception.unexpected/bad.exception/bad_exception.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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); +} diff --git a/libcxx/test/language.support/support.exception/exception.unexpected/nothing_to_do.pass.cpp b/libcxx/test/language.support/support.exception/exception.unexpected/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..fa4d462f18d --- /dev/null +++ b/libcxx/test/language.support/support.exception/exception.unexpected/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/language.support/support.exception/exception.unexpected/set.unexpected/set_unexpected.pass.cpp b/libcxx/test/language.support/support.exception/exception.unexpected/set.unexpected/set_unexpected.pass.cpp new file mode 100644 index 00000000000..6f52ab772aa --- /dev/null +++ b/libcxx/test/language.support/support.exception/exception.unexpected/set.unexpected/set_unexpected.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test set_unexpected + +#include <exception> +#include <cassert> + +void f1() {} +void f2() {} + +int main() +{ + assert(std::set_unexpected(f1) == std::terminate); + assert(std::set_unexpected(f2) == f1); +} diff --git a/libcxx/test/language.support/support.exception/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp b/libcxx/test/language.support/support.exception/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp new file mode 100644 index 00000000000..dbb56069d48 --- /dev/null +++ b/libcxx/test/language.support/support.exception/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp @@ -0,0 +1,19 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test unexpected_handler + +#include <exception> + +void f() {} + +int main() +{ + std::unexpected_handler p = f; +} diff --git a/libcxx/test/language.support/support.exception/exception.unexpected/unexpected/unexpected.pass.cpp b/libcxx/test/language.support/support.exception/exception.unexpected/unexpected/unexpected.pass.cpp new file mode 100644 index 00000000000..0f441e2b6e7 --- /dev/null +++ b/libcxx/test/language.support/support.exception/exception.unexpected/unexpected/unexpected.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test unexpected + +#include <exception> +#include <cstdlib> +#include <cassert> + +void f1() +{ + std::exit(0); +} + +int main() +{ + std::set_unexpected(f1); + std::unexpected(); + assert(false); +} diff --git a/libcxx/test/language.support/support.exception/exception/exception.pass.cpp b/libcxx/test/language.support/support.exception/exception/exception.pass.cpp new file mode 100644 index 00000000000..d3ad7e4b280 --- /dev/null +++ b/libcxx/test/language.support/support.exception/exception/exception.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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); +} diff --git a/libcxx/test/language.support/support.exception/propagation/current_exception.pass.cpp b/libcxx/test/language.support/support.exception/propagation/current_exception.pass.cpp new file mode 100644 index 00000000000..95ba458df49 --- /dev/null +++ b/libcxx/test/language.support/support.exception/propagation/current_exception.pass.cpp @@ -0,0 +1,269 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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); +} diff --git a/libcxx/test/language.support/support.exception/propagation/exception_ptr.pass.cpp b/libcxx/test/language.support/support.exception/propagation/exception_ptr.pass.cpp new file mode 100644 index 00000000000..6c017688bce --- /dev/null +++ b/libcxx/test/language.support/support.exception/propagation/exception_ptr.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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); +} diff --git a/libcxx/test/language.support/support.exception/propagation/make_exception_ptr.pass.cpp b/libcxx/test/language.support/support.exception/propagation/make_exception_ptr.pass.cpp new file mode 100644 index 00000000000..794199fa567 --- /dev/null +++ b/libcxx/test/language.support/support.exception/propagation/make_exception_ptr.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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); + } +} diff --git a/libcxx/test/language.support/support.exception/propagation/rethrow_exception.pass.cpp b/libcxx/test/language.support/support.exception/propagation/rethrow_exception.pass.cpp new file mode 100644 index 00000000000..6cb19f709fa --- /dev/null +++ b/libcxx/test/language.support/support.exception/propagation/rethrow_exception.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. 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); + } +} diff --git a/libcxx/test/language.support/support.exception/uncaught/uncaught_exception.pass.cpp b/libcxx/test/language.support/support.exception/uncaught/uncaught_exception.pass.cpp new file mode 100644 index 00000000000..33ee8770464 --- /dev/null +++ b/libcxx/test/language.support/support.exception/uncaught/uncaught_exception.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// test uncaught_exception + +#include <exception> +#include <cassert> + +struct A +{ + ~A() + { + assert(std::uncaught_exception()); + } +}; + +int main() +{ + try + { + A a; + assert(!std::uncaught_exception()); + throw 1; + } + catch (...) + { + assert(!std::uncaught_exception()); + } + assert(!std::uncaught_exception()); +} diff --git a/libcxx/test/language.support/support.exception/version.pass.cpp b/libcxx/test/language.support/support.exception/version.pass.cpp new file mode 100644 index 00000000000..db3013e9f11 --- /dev/null +++ b/libcxx/test/language.support/support.exception/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <exception> + +#include <exception> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} |