2014-04-15 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / obj-c++.dg / exceptions-5.mm
blob1ea9a6f4610ec09f6d8cfbf8cb8733aa860434a3
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
2 /* { dg-options "-fobjc-exceptions" } */
3 /* { dg-do compile } */
5 /* Test that you can use an unnamed argument with @catch.  This test is the same
6    as exceptions-3.mm, but with no name for @catch arguments.  */
8 #include <objc/objc.h>
10 @interface MyObject
12   Class isa;
14 @end
16 @implementation MyObject
17 @end
19 @protocol MyProtocol;
21 typedef MyObject MyObjectTypedef;
22 typedef MyObject *MyObjectPtrTypedef;
23 typedef int intTypedef;
25 int test (id object)
27   int dummy = 0;
29   @try { @throw object; }
30   @catch (int)          /* { dg-error "@catch parameter is not a known Objective-C class type" } */
31     {
32       dummy++;
33     }
35   @try { @throw object; }
36   @catch (intTypedef)   /* { dg-error "@catch parameter is not a known Objective-C class type" } */
37     {
38       dummy++;
39     }
41   @try { @throw object; }
42   @catch (int *)         /* { dg-error "@catch parameter is not a known Objective-C class type" } */
43     {
44       dummy++;
45     }  
47   @try { @throw object; }
48   @catch (id)           /* Ok */
49     {
50       dummy++;
51     }
53   @try { @throw object; }
54   @catch (id <MyProtocol>) /* { dg-error "@catch parameter can not be protocol-qualified" } */
55     {
56       dummy++;
57     }
59   @try { @throw object; }
60   @catch (MyObject *)    /* Ok */
61     {
62       dummy++;
63     }
65   @try { @throw object; }
66   @catch (MyObject <MyProtocol> *)  /* { dg-error "@catch parameter can not be protocol-qualified" } */
67     {
68       dummy++;
69     }
71   @try { @throw object; }
72   @catch (MyObject)     /* { dg-error "@catch parameter is not a known Objective-C class type" } */
73     {                     /* { dg-error "no matching function" "" { target *-*-* } 72 } */
74       dummy++;            /* { dg-message "MyObject" "" { target *-*-* } 13 } */
75     }                     /* { dg-message "candidate" "" { target *-*-* } 13 } */
76                           /* { dg-message "candidate" "" { target *-*-* } 72 } */
78   @try { @throw object; }
79   @catch (static MyObject *) /* { dg-error "storage class" } */
80     {
81       dummy++;
82     }
84   @try { @throw object; }
85   @catch (MyObjectTypedef *) /* Ok */
86     {
87       dummy++;
88     }
90   @try { @throw object; }
91   @catch (MyObjectTypedef <MyProtocol> *) /* { dg-error "@catch parameter can not be protocol-qualified" } */
92     {
93       dummy++;
94     }
96   @try { @throw object; }
97   @catch (MyObjectPtrTypedef) /* Ok */
98     {
99       dummy++;
100     }
102   @try { @throw object; }
103   @catch (Class)   /* { dg-error "@catch parameter is not a known Objective-C class type" } */
104     {
105       dummy++;
106     }
108   @try { @throw object; }
109   @catch (...)            /* Ok */
110     {
111       dummy++;
112     }
114   return dummy;