Files
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
libcxx
libcxxabi
cmake
fuzz
include
lib
src
test
libcxxabi
native
support
CMakeLists.txt
backtrace_test.pass.cpp
catch_array_01.pass.cpp
catch_array_02.pass.cpp
catch_class_01.pass.cpp
catch_class_02.pass.cpp
catch_class_03.pass.cpp
catch_class_04.pass.cpp
catch_const_pointer_nullptr.pass.cpp
catch_function_01.pass.cpp
catch_function_02.pass.cpp
catch_function_03.pass.cpp
catch_in_noexcept.pass.cpp
catch_member_data_pointer_01.pass.cpp
catch_member_function_pointer_01.pass.cpp
catch_member_function_pointer_02.pass.cpp
catch_member_pointer_nullptr.pass.cpp
catch_multi_level_pointer.pass.cpp
catch_pointer_nullptr.pass.cpp
catch_pointer_reference.pass.cpp
catch_ptr.pass.cpp
catch_ptr_02.pass.cpp
catch_reference_nullptr.pass.cpp
cxa_bad_cast.pass.cpp
cxa_bad_typeid.pass.cpp
cxa_thread_atexit_test.pass.cpp
dynamic_cast14.pass.cpp
dynamic_cast3.pass.cpp
dynamic_cast5.pass.cpp
dynamic_cast_stress.pass.cpp
exception_object_alignment.pass.cpp
incomplete_type.sh.cpp
inherited_exception.pass.cpp
lit.cfg
lit.site.cfg.in
noexception1.pass.cpp
noexception2.pass.cpp
noexception3.pass.cpp
noexception4.pass.cpp
test_aux_runtime.pass.cpp
test_aux_runtime_op_array_new.pass.cpp
test_demangle.pass.cpp.REMOVED.git-id
test_exception_address_alignment.pass.cpp
test_exception_storage.pass.cpp
test_fallback_malloc.pass.cpp
test_guard.pass.cpp
test_vector1.pass.cpp
test_vector2.pass.cpp
test_vector3.pass.cpp
testit
thread_local_destruction_order.pass.cpp
uncaught_exceptions.pass.cpp
unittest_demangle.pass.cpp
unwind_01.pass.cpp
unwind_02.pass.cpp
unwind_03.pass.cpp
unwind_04.pass.cpp
unwind_05.pass.cpp
unwind_06.pass.cpp
www
.arcconfig
.clang-format
.gitignore
CMakeLists.txt
CREDITS.TXT
LICENSE.TXT
libunwind
lld
lldb
llvm
openmp
polly
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mk
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
linux-packaging-mono/external/llvm-project/libcxxabi/test/catch_ptr_02.pass.cpp

215 lines
3.0 KiB
C++
Raw Normal View History

//===------------------------- catch_ptr_02.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: libcxxabi-no-exceptions
#include <cassert>
// Clang emits warnings about exceptions of type 'Child' being caught by
// an earlier handler of type 'Base'. Congrats clang, you've just
// diagnosed the behavior under test.
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wexceptions"
#endif
#if __cplusplus < 201103L
#define DISABLE_NULLPTR_TESTS
#endif
struct A {};
A a;
const A ca = A();
void test1 ()
{
try
{
throw &a;
assert(false);
}
catch ( const A* )
{
}
catch ( A *)
{
assert (false);
}
}
void test2 ()
{
try
{
throw &a;
assert(false);
}
catch ( A* )
{
}
catch ( const A *)
{
assert (false);
}
}
void test3 ()
{
try
{
throw &ca;
assert(false);
}
catch ( const A* )
{
}
catch ( A *)
{
assert (false);
}
}
void test4 ()
{
try
{
throw &ca;
assert(false);
}
catch ( A *)
{
assert (false);
}
catch ( const A* )
{
}
}
struct base1 {int x;};
struct base2 {int x;};
struct derived : base1, base2 {};
void test5 ()
{
try
{
throw (derived*)0;
assert(false);
}
catch (base2 *p) {
assert (p == 0);
}
catch (...)
{
assert (false);
}
}
void test6 ()
{
#if !defined(DISABLE_NULLPTR_TESTS)
try
{
throw nullptr;
assert(false);
}
catch (base2 *p) {
assert (p == nullptr);
}
catch (...)
{
assert (false);
}
#endif
}
void test7 ()
{
try
{
throw (derived*)12;
assert(false);
}
catch (base2 *p) {
assert ((unsigned long)p == 12+sizeof(base1));
}
catch (...)
{
assert (false);
}
}
struct vBase {};
struct vDerived : virtual public vBase {};
void test8 ()
{
vDerived derived;
try
{
throw &derived;
assert(false);
}
catch (vBase *p) {
assert(p != 0);
}
catch (...)
{
assert (false);
}
}
void test9 ()
{
#if !defined(DISABLE_NULLPTR_TESTS)
try
{
throw nullptr;
assert(false);
}
catch (vBase *p) {
assert(p == 0);
}
catch (...)
{
assert (false);
}
#endif
}
void test10 ()
{
try
{
throw (vDerived*)0;
assert(false);
}
catch (vBase *p) {
assert(p == 0);
}
catch (...)
{
assert (false);
}
}
int main()
{
test1();
test2();
test3();
test4();
test5();
test6();
test7();
test8();
test9();
test10();
}