xref: /aosp_15_r20/external/clang/test/Parser/objc-try-catch-1.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s
2*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions -x objective-c++ %s
3*67e74705SXin Livoid * proc();
4*67e74705SXin Li
5*67e74705SXin Li@interface NSConstantString
6*67e74705SXin Li@end
7*67e74705SXin Li
8*67e74705SXin Li@interface Frob
9*67e74705SXin Li@end
10*67e74705SXin Li
11*67e74705SXin Li@interface Frob1
12*67e74705SXin Li@end
13*67e74705SXin Li
14*67e74705SXin Livoid * foo()
15*67e74705SXin Li{
16*67e74705SXin Li  @try {
17*67e74705SXin Li    return proc();
18*67e74705SXin Li  }
19*67e74705SXin Li  @catch (Frob* ex) {
20*67e74705SXin Li    @throw;
21*67e74705SXin Li  }
22*67e74705SXin Li  @catch (Frob1* ex) {
23*67e74705SXin Li    @throw proc();
24*67e74705SXin Li  }
25*67e74705SXin Li  @finally {
26*67e74705SXin Li    @try {
27*67e74705SXin Li      return proc();
28*67e74705SXin Li    }
29*67e74705SXin Li    @catch (Frob* ex) {
30*67e74705SXin Li      @throw 1,2; // expected-error {{@throw requires an Objective-C object type ('int' invalid)}} \
31*67e74705SXin Li				  // expected-warning {{expression result unused}}
32*67e74705SXin Li    }
33*67e74705SXin Li    @catch (float x) {  // expected-error {{@catch parameter is not a pointer to an interface type}}
34*67e74705SXin Li
35*67e74705SXin Li    }
36*67e74705SXin Li    @catch(...) {
37*67e74705SXin Li      @throw (4,3,proc()); // expected-warning {{expression result unused}} \
38*67e74705SXin Li						   // expected-warning {{expression result unused}}
39*67e74705SXin Li    }
40*67e74705SXin Li  }
41*67e74705SXin Li
42*67e74705SXin Li  @try {  // expected-error {{@try statement without a @catch and @finally clause}}
43*67e74705SXin Li    return proc();
44*67e74705SXin Li  }
45*67e74705SXin Li}
46*67e74705SXin Li
47*67e74705SXin Li
48*67e74705SXin Livoid bar()
49*67e74705SXin Li{
50*67e74705SXin Li  @try {}// expected-error {{@try statement without a @catch and @finally clause}}
51*67e74705SXin Li  @"s"; //  expected-warning {{result unused}}
52*67e74705SXin Li}
53*67e74705SXin Li
54*67e74705SXin Livoid baz()
55*67e74705SXin Li{
56*67e74705SXin Li  @try {}// expected-error {{@try statement without a @catch and @finally clause}}
57*67e74705SXin Li  @try {}
58*67e74705SXin Li  @finally {}
59*67e74705SXin Li}
60*67e74705SXin Li
61*67e74705SXin Livoid noTwoTokenLookAheadRequiresABitOfFancyFootworkInTheParser() {
62*67e74705SXin Li    @try {
63*67e74705SXin Li        // Do something
64*67e74705SXin Li    } @catch (...) {}
65*67e74705SXin Li    @try {
66*67e74705SXin Li        // Do something
67*67e74705SXin Li    } @catch (...) {}
68*67e74705SXin Li    return;
69*67e74705SXin Li}
70*67e74705SXin Li
71