[cfe-commits] [libcxxabi] r149530 - in /libcxxabi/trunk: src/private_typeinfo.cpp test/catch_function_01.cpp test/catch_function_02.cpp

Howard Hinnant hhinnant at apple.com
Wed Feb 1 11:42:46 PST 2012


Author: hhinnant
Date: Wed Feb  1 13:42:45 2012
New Revision: 149530

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

Added:
    libcxxabi/trunk/test/catch_function_01.cpp
    libcxxabi/trunk/test/catch_function_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=149530&r1=149529&r2=149530&view=diff
==============================================================================
--- libcxxabi/trunk/src/private_typeinfo.cpp (original)
+++ libcxxabi/trunk/src/private_typeinfo.cpp Wed Feb  1 13:42:45 2012
@@ -249,7 +249,10 @@
 __function_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 a function by reference.
+    //   However if someone tries to throw a function, it immediately gets
+    //   converted to a pointer, which will not convert back to a function
+    //   at the catch clause.  So this can never catch anything.
     return false;
 }
 

Added: libcxxabi/trunk/test/catch_function_01.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/catch_function_01.cpp?rev=149530&view=auto
==============================================================================
--- libcxxabi/trunk/test/catch_function_01.cpp (added)
+++ libcxxabi/trunk/test/catch_function_01.cpp Wed Feb  1 13:42:45 2012
@@ -0,0 +1,31 @@
+//===----------------------- catch_function_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>
+
+void f() {}
+
+int main()
+{
+    typedef void Function();
+    try
+    {
+        throw f;     // converts to void (*)()
+        assert(false);
+    }
+    catch (Function& b)  // can't catch void (*)()
+    {
+        assert(false);
+    }
+    catch (...)
+    {
+    }
+}

Added: libcxxabi/trunk/test/catch_function_02.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/catch_function_02.cpp?rev=149530&view=auto
==============================================================================
--- libcxxabi/trunk/test/catch_function_02.cpp (added)
+++ libcxxabi/trunk/test/catch_function_02.cpp Wed Feb  1 13:42:45 2012
@@ -0,0 +1,31 @@
+//===---------------------- catch_function_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>
+
+void f() {}
+
+int main()
+{
+    typedef void Function();
+    try
+    {
+        throw f;     // converts to void (*)()
+        assert(false);
+    }
+    catch (Function b)  // equivalent to void (*)()
+    {
+    }
+    catch (...)
+    {
+        assert(false);
+    }
+}





More information about the cfe-commits mailing list