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} /* { dg-line interface_MyObject } */
14@end
15
16@implementation MyObject
17@end
18
19@protocol MyProtocol;
20
21typedef MyObject MyObjectTypedef;
22typedef MyObject *MyObjectPtrTypedef;
23typedef int intTypedef;
24
25int test (id object)
26{
27  int dummy = 0;
28
29  @try { @throw object; }
30  @catch (int x)          /* { dg-error "@catch parameter is not a known Objective-C class type" } */
31    {
32      dummy++;
33    }
34
35  @try { @throw object; }
36  @catch (intTypedef x)   /* { dg-error "@catch parameter is not a known Objective-C class type" } */
37    {
38      dummy++;
39    }
40
41  @try { @throw object; }
42  @catch (int *x)         /* { dg-error "@catch parameter is not a known Objective-C class type" } */
43    {
44      dummy++;
45    }
46
47  @try { @throw object; }
48  @catch (id x)           /* Ok */
49    {
50      dummy++;
51    }
52
53  @try { @throw object; }
54  @catch (id <MyProtocol> x) /* { dg-error "@catch parameter can not be protocol-qualified" } */
55    {
56      dummy++;
57    }
58
59  @try { @throw object; }
60  @catch (MyObject *x)    /* Ok */
61    {
62      dummy++;
63    }
64
65  @try { @throw object; }
66  @catch (MyObject <MyProtocol> *x)  /* { dg-error "@catch parameter can not be protocol-qualified" } */
67    {
68      dummy++;
69    }
70
71  @try { @throw object; }
72  @catch (MyObject x)     /* { dg-error "@catch parameter is not a known Objective-C class type" } */
73    {                     /* { dg-error "no matching function" "" { target *-*-* } .-1 } */
74      dummy++;            /* { dg-message "MyObject" "" { target *-*-* } interface_MyObject } */
75    }                     /* { dg-message "candidate" "" { target *-*-* } interface_MyObject } */
76  @try { @throw object; }
77  @catch (static MyObject *x) /* { dg-error "storage class" } */
78    {
79      dummy++;
80    }
81
82  @try { @throw object; }
83  @catch (MyObjectTypedef *x) /* Ok */
84    {
85      dummy++;
86    }
87
88  @try { @throw object; }
89  @catch (MyObjectTypedef <MyProtocol> *x) /* { dg-error "@catch parameter can not be protocol-qualified" } */
90    {
91      dummy++;
92    }
93
94  @try { @throw object; }
95  @catch (MyObjectPtrTypedef x) /* Ok */
96    {
97      dummy++;
98    }
99
100  @try { @throw object; }
101  @catch (Class x)   /* { dg-error "@catch parameter is not a known Objective-C class type" } */
102    {
103      dummy++;
104    }
105
106  @try { @throw object; }
107  @catch (...)            /* Ok */
108    {
109      dummy++;
110    }
111
112  return dummy;
113}
114