PR tree-optimization/81303
[official-gcc.git] / gcc / testsuite / obj-c++.dg / exceptions-2.mm
blobc66d39ebca2cd98abe9c1990212e300ee4be232c
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
3 /* FIXME: This does not test running the code, because Objective-C exceptions at the moment
4    do not execute correctly in Objective-C++.  See PR objc++/23616.  Once that is fixed,
5    this test should be changed to use 'dg-do run' instead of just 'dg-do compile'.  */
6 /* { dg-do compile } */
7 /* { dg-options "-fobjc-exceptions" } */
9 /* This test checks the syntax @catch (...) which catches any
10    exceptions.  Check that code using it runs correctly.  */
12 #include "../objc-obj-c++-shared/TestsuiteObject.m"
13 #include <stdlib.h>
15 @interface MyObject : TestsuiteObject
16 @end
18 @implementation MyObject
19 @end
21 int test (id object)
23   int i = 0;
25   @try
26     {
27       @throw object;
28     }
29   @catch (MyObject *o)
30     {
31       i += 1;
32     }
33   @catch (...)
34     {
35       i += 2;
36     }
37   @finally
38     {
39       i += 4;
40     }
42   return i;
45 int main (void)
47   if (test ([MyObject new]) != 5)
48     abort ();
50   if (test ([TestsuiteObject new]) != 6)
51     abort ();
53   return 0;