PR target/83368
[official-gcc.git] / gcc / testsuite / obj-c++.dg / exceptions-4.mm
blob104ad0e7fe164dbdf6eb4169983c5b3b57f156b3
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
2 /* { dg-options "-fobjc-exceptions" } */
3 /* { dg-do compile } */
5 /* Test warnings when parsing syntax errors in @catch().  */
7 #include <objc/objc.h>
9 @interface MyObject
11   Class isa;
13 @end
15 @implementation MyObject
16 @end
18 @interface MyObject2
20   Class isa;
22 @end
24 @implementation MyObject2
25 @end
27 @protocol MyProtocol;
29 int test (id object)
31   int dummy = 0;
33   @try { @throw object; }
34   @catch
35     {          /* { dg-error "expected" } */
36       dummy++; /* { dg-error "@catch parameter is not a known Objective-C class type" "" { target *-*-* } .-1 } */
37     }
38   @catch ()  /* { dg-error "expected identifier before" } */
39     {        /* { dg-error "@catch parameter is not a known Objective-C class type" "" { target *-*-* } .-1 } */
40       dummy++;
41     }
42   @catch (i) /* { dg-error ".i. has not been declared" } */
43     {        /* { dg-error "@catch parameter is not a known Objective-C class type" "" { target *-*-* } .-1 } */
44       dummy++;
45     }
46   @catch (id <MyProtocol x) /* { dg-error "expected ... before .x." } */
47     {                       /* { dg-error "@catch parameter can not be protocol-qualified" "" { target *-*-* } .-1 } */
48       dummy++;
49     }
50   @catch MyObject *x       /* { dg-error "expected ... before .MyObject." } */
51     {
52       dummy++;
53     }
54   @catch MyObject2 *x)     /* { dg-error "expected ... before .MyObject2." } */
55    {
56      dummy++;
57    }
59   @try { @throw object; }
60   @catch (MyObject *x)
61   @catch (MyObject2 *y)    /* { dg-error "expected ... before .catch." } */
63   return dummy;            /* { dg-error "expected ... before .return." } */