Daily bump.
[official-gcc.git] / gcc / testsuite / obj-c++.dg / exceptions-5.mm
blob4547a756c74050398472a602995277a471daa69c
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
2 /* { dg-options "-fobjc-exceptions" } */
3 /* { dg-do compile } */
4 // { dg-additional-options "-Wno-objc-root-class" }
6 /* Test that you can use an unnamed argument with @catch.  This test is the same
7    as exceptions-3.mm, but with no name for @catch arguments.  */
9 #include <objc/objc.h>
11 @interface MyObject
13   Class isa;
14 } /* { dg-line interface_MyObject } */
15 @end
17 @implementation MyObject
18 @end
20 @protocol MyProtocol;
22 typedef MyObject MyObjectTypedef;
23 typedef MyObject *MyObjectPtrTypedef;
24 typedef int intTypedef;
26 int test (id object)
28   int dummy = 0;
30   @try { @throw object; }
31   @catch (int)          /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
32     {
33       dummy++;
34     }
36   @try { @throw object; }
37   @catch (intTypedef)   /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
38     {
39       dummy++;
40     }
42   @try { @throw object; }
43   @catch (int *)         /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
44     {
45       dummy++;
46     }  
48   @try { @throw object; }
49   @catch (id)           /* Ok */
50     {
51       dummy++;
52     }
54   @try { @throw object; }
55   @catch (id <MyProtocol>) /* { dg-error "'@catch' parameter cannot be protocol-qualified" } */
56     {
57       dummy++;
58     }
60   @try { @throw object; }
61   @catch (MyObject *)    /* Ok */
62     {
63       dummy++;
64     }
66   @try { @throw object; }
67   @catch (MyObject <MyProtocol> *)  /* { dg-error "'@catch' parameter cannot be protocol-qualified" } */
68     {
69       dummy++;
70     }
72   @try { @throw object; }
73   @catch (MyObject)     /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
74     {                     /* { dg-error "no matching function" "" { target *-*-* } .-1 } */
75       dummy++;            /* { dg-message "MyObject" "" { target *-*-* } interface_MyObject } */
76     }                     /* { dg-message "candidate" "" { target *-*-* } interface_MyObject } */
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 cannot 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;