xref: /aosp_15_r20/external/clang/test/SemaObjC/try-catch.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s
2*67e74705SXin Litypedef signed char BOOL;
3*67e74705SXin Litypedef struct _NSZone NSZone;
4*67e74705SXin Li
5*67e74705SXin Li@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
6*67e74705SXin Li
7*67e74705SXin Li@protocol NSObject
8*67e74705SXin Li- (BOOL)isEqual:(id)object;
9*67e74705SXin Li@end
10*67e74705SXin Li
11*67e74705SXin Li@protocol NSCopying
12*67e74705SXin Li- (id)copyWithZone:(NSZone *)zone;
13*67e74705SXin Li@end
14*67e74705SXin Li
15*67e74705SXin Li@protocol NSCoding
16*67e74705SXin Li- (void)encodeWithCoder:(NSCoder *)aCoder;
17*67e74705SXin Li@end
18*67e74705SXin Li
19*67e74705SXin Li@interface NSObject <NSObject> {}
20*67e74705SXin Li@end
21*67e74705SXin Li
22*67e74705SXin Li@class NSData, NSArray, NSDictionary, NSCharacterSet, NSData, NSURL, NSError, NSLocale;
23*67e74705SXin Li
24*67e74705SXin Li@interface NSException : NSObject <NSCopying, NSCoding> {}
25*67e74705SXin Li@end
26*67e74705SXin Li
27*67e74705SXin Li@class ASTNode, XCRefactoringParser, Transform, TransformInstance, XCRefactoringSelectionInfo;
28*67e74705SXin Li
29*67e74705SXin Li@interface XCRefactoringTransformation : NSObject {}
30*67e74705SXin Li@end
31*67e74705SXin Li
32*67e74705SXin Li@implementation XCRefactoringTransformation
33*67e74705SXin Li- (NSDictionary *)setUpInfoForTransformKey:(NSString *)transformKey outError:(NSError **)outError {
34*67e74705SXin Li    @try {}
35*67e74705SXin Li    // the exception name is optional (weird)
36*67e74705SXin Li    @catch (NSException *) {}
37*67e74705SXin Li}
38*67e74705SXin Li@end
39*67e74705SXin Li
40*67e74705SXin Liint foo() {
41*67e74705SXin Li  struct s { int a, b; } agg, *pagg;
42*67e74705SXin Li
43*67e74705SXin Li  @throw 42; // expected-error {{@throw requires an Objective-C object type ('int' invalid)}}
44*67e74705SXin Li  @throw agg; // expected-error {{@throw requires an Objective-C object type ('struct s' invalid)}}
45*67e74705SXin Li  @throw pagg; // expected-error {{@throw requires an Objective-C object type ('struct s *' invalid)}}
46*67e74705SXin Li  @throw; // expected-error {{@throw (rethrow) used outside of a @catch block}}
47*67e74705SXin Li}
48