[cfe-commits] [libcxxabi] r149527 - in /libcxxabi/trunk: src/private_typeinfo.cpp test/catch_array_01.cpp test/catch_array_02.cpp

Howard Hinnant hhinnant at apple.com
Wed Feb 1 11:21:29 PST 2012


Author: hhinnant
Date: Wed Feb  1 13:21:28 2012
New Revision: 149527

URL: http://llvm.org/viewvc/llvm-project?rev=149527&view=rev
Log:
Quash TODO regarding catch by array type.  Add tests to back it up.

Added:
    libcxxabi/trunk/test/catch_array_01.cpp
    libcxxabi/trunk/test/catch_array_02.cpp
Modified:
    libcxxabi/trunk/src/private_typeinfo.cpp

Modified: libcxxabi/trunk/src/private_typeinfo.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/private_typeinfo.cpp?rev=149527&r1=149526&r2=149527&view=diff
==============================================================================
--- libcxxabi/trunk/src/private_typeinfo.cpp (original)
+++ libcxxabi/trunk/src/private_typeinfo.cpp Wed Feb  1 13:21:28 2012
@@ -238,7 +238,10 @@
 __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;
 }
 

Added: libcxxabi/trunk/test/catch_array_01.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/catch_array_01.cpp?rev=149527&view=auto
==============================================================================
--- libcxxabi/trunk/test/catch_array_01.cpp (added)
+++ libcxxabi/trunk/test/catch_array_01.cpp Wed Feb  1 13:21:28 2012
@@ -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 <cassert>
+
+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 (...)
+    {
+    }
+}

Added: libcxxabi/trunk/test/catch_array_02.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/catch_array_02.cpp?rev=149527&view=auto
==============================================================================
--- libcxxabi/trunk/test/catch_array_02.cpp (added)
+++ libcxxabi/trunk/test/catch_array_02.cpp Wed Feb  1 13:21:28 2012
@@ -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 <cassert>
+
+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);
+    }
+}





More information about the cfe-commits mailing list