blob: 31796bc4c5cd167cf51d82296a901d0fc6ab8872 [file] [log] [blame]
Nicola Pero437c2322010-11-29 03:15:40 +00001/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
2/* { dg-options "-fobjc-exceptions" } */
3/* { dg-do compile } */
Iain Sandoed35fbf72020-11-12 13:11:11 +00004/* { dg-additional-options "-Wno-objc-root-class" } */
Nicola Pero437c2322010-11-29 03:15:40 +00005
6/* Test that you can use an unnamed argument with @catch. This test is the same
7 as exceptions-3.m, but with no name for @catch arguments. */
8
9#include <objc/objc.h>
10
11@interface MyObject
12{
13 Class isa;
14}
15@end
16
17@implementation MyObject
18@end
19
20@protocol MyProtocol;
21
22typedef MyObject MyObjectTypedef;
23typedef MyObject *MyObjectPtrTypedef;
24typedef int intTypedef;
25
26int test (id object)
27{
28 int dummy = 0;
29
30 @try { @throw object; }
Martin Sebora9c697b2019-05-17 17:55:43 +000031 @catch (int) /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
Nicola Pero437c2322010-11-29 03:15:40 +000032 {
33 dummy++;
34 }
35
36 @try { @throw object; }
Martin Sebora9c697b2019-05-17 17:55:43 +000037 @catch (intTypedef) /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
Nicola Pero437c2322010-11-29 03:15:40 +000038 {
39 dummy++;
40 }
41
42 @try { @throw object; }
Martin Sebora9c697b2019-05-17 17:55:43 +000043 @catch (int *) /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
Nicola Pero437c2322010-11-29 03:15:40 +000044 {
45 dummy++;
46 }
47
48 @try { @throw object; }
49 @catch (id) /* Ok */
50 {
51 dummy++;
52 }
53
54 @try { @throw object; }
Martin Sebora9c697b2019-05-17 17:55:43 +000055 @catch (id <MyProtocol>) /* { dg-error "'@catch' parameter cannot be protocol-qualified" } */
Nicola Pero437c2322010-11-29 03:15:40 +000056 {
57 dummy++;
58 }
59
60 @try { @throw object; }
61 @catch (MyObject *) /* Ok */
62 {
63 dummy++;
64 }
65
66 @try { @throw object; }
Martin Sebora9c697b2019-05-17 17:55:43 +000067 @catch (MyObject <MyProtocol> *) /* { dg-error "'@catch' parameter cannot be protocol-qualified" } */
Nicola Pero437c2322010-11-29 03:15:40 +000068 {
69 dummy++;
70 }
71
72 @try { @throw object; }
Martin Sebora9c697b2019-05-17 17:55:43 +000073 @catch (MyObject) /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
Tom de Vries6143c992017-04-19 06:55:33 +000074 { /* { dg-error "conversion to non-scalar type requested" "" { target *-*-* } .-1 } */
Nicola Pero437c2322010-11-29 03:15:40 +000075 dummy++;
76 }
77
78 @try { @throw object; }
79 @catch (static MyObject *) /* { dg-error "storage class specified for" } */
80 {
81 dummy++;
82 }
83
84 @try { @throw object; }
85 @catch (MyObjectTypedef *) /* Ok */
86 {
87 dummy++;
88 }
89
90 @try { @throw object; }
Martin Sebora9c697b2019-05-17 17:55:43 +000091 @catch (MyObjectTypedef <MyProtocol> *) /* { dg-error "'@catch' parameter cannot be protocol-qualified" } */
Nicola Pero437c2322010-11-29 03:15:40 +000092 {
93 dummy++;
94 }
95
96 @try { @throw object; }
97 @catch (MyObjectPtrTypedef) /* Ok */
98 {
99 dummy++;
100 }
101
102 @try { @throw object; }
Martin Sebora9c697b2019-05-17 17:55:43 +0000103 @catch (Class) /* { dg-error "'@catch' parameter is not a known Objective-C class type" } */
Nicola Pero437c2322010-11-29 03:15:40 +0000104 {
105 dummy++;
106 }
107
108 @try { @throw object; }
109 @catch (...) /* Ok */
110 {
111 dummy++;
112 }
113
114 return dummy;
115}