1 // RUN: %clang_analyze_cc1 -verify -Wno-objc-root-class %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=nullability \
4 // RUN: -analyzer-checker=osx.cocoa.NSError \
5 // RUN: -analyzer-checker=osx.coreFoundation.CFError
7 typedef signed char BOOL;
9 typedef struct _NSZone NSZone;
10 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
11 @protocol NSObject - (BOOL)isEqual:(id)object; @end
12 @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
13 @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
14 @interface NSObject <NSObject> {} @end
16 @interface NSError : NSObject <NSCopying, NSCoding> {}
17 + (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)dict;
19 extern NSString * const NSXMLParserErrorDomain ;
22 - (void)myMethodWhichMayFail:(NSError **)error;
23 - (BOOL)myMethodWhichMayFail2:(NSError **)error;
24 - (BOOL)myMethodWhichMayFail3:(NSError **_Nonnull)error;
25 - (BOOL)myMethodWhichMayFail4:(NSError **)error __attribute__((nonnull));
29 - (void)myMethodWhichMayFail:(NSError **)error { // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occurred}}
30 *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference. According to coding standards in 'Creating and Returning NSError Objects' the parameter may be null [osx.cocoa.NSError]}}
33 - (BOOL)myMethodWhichMayFail2:(NSError **)error { // no-warning
34 if (error) *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning
38 - (BOOL)myMethodWhichMayFail3:(NSError **_Nonnull)error { // no-warning
39 *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning
43 - (BOOL)myMethodWhichMayFail4:(NSError **)error { // no-warning
44 *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning
50 typedef struct __CFError* CFErrorRef;
52 void foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred}}
53 *error = 0; // expected-warning {{Potential null dereference. According to coding standards documented in CoreFoundation/CFError.h the parameter may be null [osx.coreFoundation.CFError]}}
56 int f1(CFErrorRef* error) {
57 if (error) *error = 0; // no-warning
61 int f2(CFErrorRef* error) {
62 if (0 != error) *error = 0; // no-warning
66 int f3(CFErrorRef* error) {
67 if (error != 0) *error = 0; // no-warning
71 int __attribute__((nonnull)) f4(CFErrorRef *error) {
72 *error = 0; // no-warning
76 int __attribute__((nonnull(1))) f5(int *x, CFErrorRef *error) {
77 *error = 0; // expected-warning {{Potential null dereference. According to coding standards documented in CoreFoundation/CFError.h the parameter may be null [osx.coreFoundation.CFError]}}
81 int __attribute__((nonnull(2))) f6(int *x, CFErrorRef *error) {
82 *error = 0; // no-warning