diff options
author | Asiri Rathnayake <asiri.rathnayake@arm.com> | 2016-05-31 12:01:32 +0000 |
---|---|---|
committer | Asiri Rathnayake <asiri.rathnayake@arm.com> | 2016-05-31 12:01:32 +0000 |
commit | 4174e8b402ba05e3b3e003b1066f1eae6fbeb24b (patch) | |
tree | 00a63addfb8fc122d9d3f275d22d2541ea4a63e2 /test/cxa_bad_typeid.pass.cpp | |
parent | 436072f52ff05d69f626a9c7a309a1464758f129 (diff) |
[libcxxabi] Introduce a -fno-exceptions libc++abi libary variant
Currently there is only support for a -fno-exceptions libc++ build. This is
problematic for functions such as std::terminate() which are defined in
libc++abi and using any of those functions throws away most of the benefits
of using -fno-exceptions (code-size). This patch introduces a -fno-exceptions
libc++abi build to address this issue.
This new variant of libc++abi cannot be linked against any with-exceptions
code as some symbols necessary for handling exceptions are missing in this
library.
Differential revision: http://reviews.llvm.org/D20677
Reviewers: EricWF, mclow.lists, bcraig
git-svn-id: https://llvm.org/svn/llvm-project/libcxxabi/trunk@271267 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/cxa_bad_typeid.pass.cpp')
-rw-r--r-- | test/cxa_bad_typeid.pass.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/cxa_bad_typeid.pass.cpp b/test/cxa_bad_typeid.pass.cpp new file mode 100644 index 0000000..d747ff2 --- /dev/null +++ b/test/cxa_bad_typeid.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------- cxa_bad_typeid.pass.cpp ------------------------===// +// +// 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. +// +//===------------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +#include <cxxabi.h> +#include <cassert> +#include <stdlib.h> +#include <exception> +#include <typeinfo> +#include <string> +#include <iostream> + +class Base { + virtual void foo() {}; +}; + +class Derived : public Base {}; + +std::string test_bad_typeid(Derived *p) { + typeid(*p).name(); +} + +void my_terminate() { std::cout << "A" << std::endl; exit(0); } + +int main () +{ + // swap-out the terminate handler + void (*default_handler)() = std::get_terminate(); + std::set_terminate(my_terminate); + +#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS + try { +#endif + test_bad_typeid(nullptr); + assert(false); +#ifndef LIBCXXABI_HAS_NO_EXCEPTIONS + } catch (std::bad_typeid) { + // success + return 0; + } catch (...) { + assert(false); + } +#endif + + // failure, restore the default terminate handler and fire + std::set_terminate(default_handler); + std::terminate(); +} |