Debian Codegraph @

gcc/testsuite/obj-c++.dg/exceptions-3.mm

raw
1 /* Contributed by Nicola Pero <[email protected]>, November 2010. */
2 /* { dg-options "-fobjc-exceptions" } */
3 /* { dg-do compile } */
4 // { dg-additional-options "-Wno-objc-root-class" }
5
6 /* Test that the compiler is checking the argument of @catch(), and
7 produce errors when invalid types are used. */
8
9 #include <objc/objc.h>
10
11 @interface MyObject
12 {
13 Class isa;
14 } /* { dg-line interface_MyObject } */
15 @end
16
17 @implementation MyObject
18 @end
19
20 @protocol MyProtocol;
21
22 typedef MyObject MyObjectTypedef;
23 typedef MyObject *MyObjectPtrTypedef;
24 typedef int intTypedef;
25
26 int test (id object)
27 {
28 int dummy = 0;
29
30 @try { @throw object; }
31 @catch (int x) /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
32 {
33 dummy++;
34 }
35
36 @try { @throw object; }
37 @catch (intTypedef x) /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
38 {
39 dummy++;
40 }
41
42 @try { @throw object; }
43 @catch (int *x) /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
44 {
45 dummy++;
46 }
47
48 @try { @throw object; }
49 @catch (id x) /* Ok */
50 {
51 dummy++;
52 }
53
54 @try { @throw object; }
55 @catch (id <MyProtocol> x) /* { dg-error "'@catch' parameter cannot be protocol-qualified" } */
56 {
57 dummy++;
58 }
59
60 @try { @throw object; }
61 @catch (MyObject *x) /* Ok */
62 {
63 dummy++;
64 }
65
66 @try { @throw object; }
67 @catch (MyObject <MyProtocol> *x) /* { dg-error "'@catch' parameter cannot be protocol-qualified" } */
68 {
69 dummy++;
70 }
71
72 @try { @throw object; }
73 @catch (MyObject x) /* { 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 } */
77 @try { @throw object; }
78 @catch (static MyObject *x) /* { dg-error "storage class" } */
79 {
80 dummy++;
81 }
82
83 @try { @throw object; }
84 @catch (MyObjectTypedef *x) /* Ok */
85 {
86 dummy++;
87 }
88
89 @try { @throw object; }
90 @catch (MyObjectTypedef <MyProtocol> *x) /* { dg-error "'@catch' parameter cannot be protocol-qualified" } */
91 {
92 dummy++;
93 }
94
95 @try { @throw object; }
96 @catch (MyObjectPtrTypedef x) /* Ok */
97 {
98 dummy++;
99 }
100
101 @try { @throw object; }
102 @catch (Class x) /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
103 {
104 dummy++;
105 }
106
107 @try { @throw object; }
108 @catch (...) /* Ok */
109 {
110 dummy++;
111 }
112
113 return dummy;
114 }