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