xref: /aosp_15_r20/external/clang/test/Rewriter/rewrite-modern-throw.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
2*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions  -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
3*67e74705SXin Li
4*67e74705SXin Litypedef struct objc_class *Class;
5*67e74705SXin Litypedef struct objc_object {
6*67e74705SXin Li    Class isa;
7*67e74705SXin Li} *id;
8*67e74705SXin Li
9*67e74705SXin Livoid *sel_registerName(const char *);
10*67e74705SXin Li
11*67e74705SXin Li@interface Foo @end
12*67e74705SXin Livoid TRY();
13*67e74705SXin Livoid SPLATCH();
14*67e74705SXin Livoid MYTRY();
15*67e74705SXin Livoid MYCATCH();
16*67e74705SXin Li
17*67e74705SXin Livoid foo() {
18*67e74705SXin Li  @try  { TRY(); }
19*67e74705SXin Li  @catch (...) { SPLATCH(); @throw; }
20*67e74705SXin Li}
21*67e74705SXin Li
22*67e74705SXin Liint main()
23*67e74705SXin Li{
24*67e74705SXin Li
25*67e74705SXin Li  @try  {
26*67e74705SXin Li     MYTRY();
27*67e74705SXin Li  }
28*67e74705SXin Li
29*67e74705SXin Li  @catch (Foo* localException) {
30*67e74705SXin Li     MYCATCH();
31*67e74705SXin Li     @throw localException;
32*67e74705SXin Li  }
33*67e74705SXin Li
34*67e74705SXin Li  // no catch clause
35*67e74705SXin Li  @try { }
36*67e74705SXin Li  @finally { }
37*67e74705SXin Li}
38*67e74705SXin Li
39*67e74705SXin Li
40*67e74705SXin Li@interface INST
41*67e74705SXin Li{
42*67e74705SXin Li  INST* throw_val;
43*67e74705SXin Li}
44*67e74705SXin Li
45*67e74705SXin Li- (id) ThrowThis;
46*67e74705SXin Li
47*67e74705SXin Li- (void) MainMeth;
48*67e74705SXin Li
49*67e74705SXin Li@end
50*67e74705SXin Li
51*67e74705SXin Li
52*67e74705SXin Li@implementation INST
53*67e74705SXin Li- (id) ThrowThis { return 0; }
54*67e74705SXin Li
55*67e74705SXin Li- (void) MainMeth {
56*67e74705SXin Li  @try  {
57*67e74705SXin Li     MYTRY();
58*67e74705SXin Li  }
59*67e74705SXin Li  @catch (Foo* localException) {
60*67e74705SXin Li     MYCATCH();
61*67e74705SXin Li     @throw [self ThrowThis];
62*67e74705SXin Li  }
63*67e74705SXin Li  @catch (...) {
64*67e74705SXin Li    @throw [throw_val ThrowThis];
65*67e74705SXin Li  }
66*67e74705SXin Li}
67*67e74705SXin Li@end
68*67e74705SXin Li
69*67e74705SXin Li// rdar://13186010
70*67e74705SXin Li@class NSDictionary, NSException;
71*67e74705SXin Li@class NSMutableDictionary;
72*67e74705SXin Li
73*67e74705SXin Li@interface NSString
74*67e74705SXin Li+ (id)stringWithFormat:(NSString *)format, ... ;
75*67e74705SXin Li@end
76*67e74705SXin Li
77*67e74705SXin Li@interface  NSException
78*67e74705SXin Li+ (NSException *)exceptionWithName:(NSString *)name reason:(NSString *)reason userInfo:(NSDictionary *)userInfo;
79*67e74705SXin Li@end
80*67e74705SXin Liid *_imp__NSInvalidArgumentException;
81*67e74705SXin Li
82*67e74705SXin Li@interface NSSetExpression @end
83*67e74705SXin Li
84*67e74705SXin Li@implementation NSSetExpression
85*67e74705SXin Li-(id)expressionValueWithObject:(id)object context:(NSMutableDictionary*)bindings {
86*67e74705SXin Li    id leftSet;
87*67e74705SXin Li    id rightSet;
88*67e74705SXin Li    @throw [NSException exceptionWithName: *_imp__NSInvalidArgumentException reason: [NSString stringWithFormat: @"Can't evaluate set expression; left subexpression not a set (lhs = %@ rhs = %@)", leftSet, rightSet] userInfo: 0];
89*67e74705SXin Li
90*67e74705SXin Li    return leftSet ;
91*67e74705SXin Li}
92*67e74705SXin Li@end
93*67e74705SXin Li
94