Ted Kremenek | 1cd920a | 2008-09-19 04:56:32 +0000 | [diff] [blame] | 1 | // RUN: clang -checker-cfref -verify %s |
| 2 | |
| 3 | typedef signed char BOOL; |
| 4 | typedef int NSInteger; |
| 5 | typedef struct _NSZone NSZone; |
| 6 | @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; |
| 7 | @protocol NSObject - (BOOL)isEqual:(id)object; @end |
| 8 | @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end |
| 9 | @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end |
| 10 | @interface NSObject <NSObject> {} @end |
| 11 | @class NSDictionary; |
| 12 | @interface NSError : NSObject <NSCopying, NSCoding> {} |
| 13 | + (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)dict; |
| 14 | @end |
| 15 | extern NSString * const NSXMLParserErrorDomain ; |
| 16 | |
| 17 | @interface A |
| 18 | - (void)myMethodWhichMayFail:(NSError **)error; |
| 19 | - (BOOL)myMethodWhichMayFail2:(NSError **)error; |
| 20 | @end |
| 21 | |
| 22 | @implementation A |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame^] | 23 | - (void)myMethodWhichMayFail:(NSError **)error { // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occured.}} |
| 24 | *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference.}} |
Ted Kremenek | 1cd920a | 2008-09-19 04:56:32 +0000 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | - (BOOL)myMethodWhichMayFail2:(NSError **)error { // no-warning |
| 28 | if (error) *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning |
| 29 | return 0; |
| 30 | } |
| 31 | @end |
Ted Kremenek | cc9ac41 | 2008-10-01 23:24:09 +0000 | [diff] [blame] | 32 | |
| 33 | struct __CFError {}; |
| 34 | typedef struct __CFError* CFErrorRef; |
| 35 | |
Chris Lattner | 0947b4e | 2008-11-24 01:28:17 +0000 | [diff] [blame^] | 36 | void foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occured.}} |
| 37 | *error = 0; // expected-warning {{Potential null dereference.}} |
Ted Kremenek | cc9ac41 | 2008-10-01 23:24:09 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | int bar(CFErrorRef* error) { |
| 41 | if (error) *error = 0; |
| 42 | return 0; |
| 43 | } |