From 26ffb64177f895e53b6c08d342e4e4608f87aee3 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Wed, 1 Feb 2012 19:21:28 +0000 Subject: [PATCH] Quash TODO regarding catch by array type. Add tests to back it up. llvm-svn: 149527 --- libcxxabi/src/private_typeinfo.cpp | 5 ++++- libcxxabi/test/catch_array_01.cpp | 30 ++++++++++++++++++++++++++++++ libcxxabi/test/catch_array_02.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 libcxxabi/test/catch_array_01.cpp create mode 100644 libcxxabi/test/catch_array_02.cpp diff --git a/libcxxabi/src/private_typeinfo.cpp b/libcxxabi/src/private_typeinfo.cpp index 6cc2f64ea670..cb7b7dc1e915 100644 --- a/libcxxabi/src/private_typeinfo.cpp +++ b/libcxxabi/src/private_typeinfo.cpp @@ -238,7 +238,10 @@ bool __array_type_info::can_catch(const __shim_type_info* thrown_type, void*&) const { - // TODO: Can this be called? + // We can get here if someone tries to catch an array by reference. + // However if someone tries to throw an array, it immediately gets + // converted to a pointer, which will not convert back to an array + // at the catch clause. So this can never catch anything. return false; } diff --git a/libcxxabi/test/catch_array_01.cpp b/libcxxabi/test/catch_array_01.cpp new file mode 100644 index 000000000000..4997602a6d0e --- /dev/null +++ b/libcxxabi/test/catch_array_01.cpp @@ -0,0 +1,30 @@ +//===---------------------- catch_array_01.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. +// +//===----------------------------------------------------------------------===// + +// Can you have a catch clause of array type that catches anything? + +#include + +int main() +{ + typedef char Array[4]; + Array a = {'H', 'i', '!', 0}; + try + { + throw a; // converts to char* + assert(false); + } + catch (Array& b) // can't catch char* + { + assert(false); + } + catch (...) + { + } +} diff --git a/libcxxabi/test/catch_array_02.cpp b/libcxxabi/test/catch_array_02.cpp new file mode 100644 index 000000000000..a06e6aaa0565 --- /dev/null +++ b/libcxxabi/test/catch_array_02.cpp @@ -0,0 +1,30 @@ +//===---------------------- catch_array_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. +// +//===----------------------------------------------------------------------===// + +// Can you have a catch clause of array type that catches anything? + +#include + +int main() +{ + typedef char Array[4]; + Array a = {'H', 'i', '!', 0}; + try + { + throw a; // converts to char* + assert(false); + } + catch (Array b) // equivalent to char* + { + } + catch (...) + { + assert(false); + } +}