Debian Codegraph @

clang/test/SemaObjC/try-catch.m

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions -Werror=return-type %s
2 typedef signed char BOOL;
3 typedef struct _NSZone NSZone;
4
5 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
6
7 @protocol NSObject
8 - (BOOL)isEqual:(id)object;
9 @end
10
11 @protocol NSCopying
12 - (id)copyWithZone:(NSZone *)zone;
13 @end
14
15 @protocol NSCoding
16 - (void)encodeWithCoder:(NSCoder *)aCoder;
17 @end
18
19 @interface NSObject <NSObject> {}
20 @end
21
22 @class NSData, NSArray, NSDictionary, NSCharacterSet, NSData, NSURL, NSError, NSLocale;
23
24 @interface NSException : NSObject <NSCopying, NSCoding> {}
25 @end
26
27 @class ASTNode, XCRefactoringParser, Transform, TransformInstance, XCRefactoringSelectionInfo;
28
29 @interface XCRefactoringTransformation : NSObject {}
30 @end
31
32 @implementation XCRefactoringTransformation
33 - (NSDictionary *)setUpInfoForTransformKey:(NSString *)transformKey outError:(NSError **)outError {
34 @try {}
35 // the exception name is optional (weird)
36 @catch (NSException *) {}
37 } // expected-error {{non-void function does not return a value}}
38
39 - (NSDictionary *)anotherFunction {
40 @try {}
41 @finally {}
42 } // FIXME: This should warn about a missing return too.
43 @end
44
45 int foo(void) {
46 struct s { int a, b; } agg, *pagg;
47
48 @throw 42; // expected-error {{@throw requires an Objective-C object type ('int' invalid)}}
49 @throw agg; // expected-error {{@throw requires an Objective-C object type ('struct s' invalid)}}
50 @throw pagg; // expected-error {{@throw requires an Objective-C object type ('struct s *' invalid)}}
51 @throw; // expected-error {{@throw (rethrow) used outside of a @catch block}}
52 }