[cfe-commits] r56332 - /cfe/trunk/test/Analysis/CheckNSError.m

Ted Kremenek kremenek at apple.com
Thu Sep 18 21:56:32 PDT 2008


Author: kremenek
Date: Thu Sep 18 23:56:32 2008
New Revision: 56332

URL: http://llvm.org/viewvc/llvm-project?rev=56332&view=rev
Log:
Added test case for PR 2600: proper use of NSError**

Added:
    cfe/trunk/test/Analysis/CheckNSError.m

Added: cfe/trunk/test/Analysis/CheckNSError.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/CheckNSError.m?rev=56332&view=auto

==============================================================================
--- cfe/trunk/test/Analysis/CheckNSError.m (added)
+++ cfe/trunk/test/Analysis/CheckNSError.m Thu Sep 18 23:56:32 2008
@@ -0,0 +1,31 @@
+// RUN: clang -checker-cfref -verify %s
+
+typedef signed char BOOL;
+typedef int NSInteger;
+typedef struct _NSZone NSZone;
+ at class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+ at protocol NSObject  - (BOOL)isEqual:(id)object; @end
+ at protocol NSCopying  - (id)copyWithZone:(NSZone *)zone; @end
+ at protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder; @end
+ at interface NSObject <NSObject> {} @end
+ at class NSDictionary;
+ at interface NSError : NSObject <NSCopying, NSCoding> {}
++ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)dict;
+ at end
+extern NSString * const NSXMLParserErrorDomain ;
+
+ at interface A
+- (void)myMethodWhichMayFail:(NSError **)error;
+- (BOOL)myMethodWhichMayFail2:(NSError **)error;
+ at end
+
+ at implementation A
+- (void)myMethodWhichMayFail:(NSError **)error {   // expected-warning: {{Method accepting NSError** argument should have non-void return value to indicate that an error occurred.}}
+  *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning: {{Potential null dereference.}}
+}
+
+- (BOOL)myMethodWhichMayFail2:(NSError **)error {  // no-warning
+  if (error) *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // no-warning
+  return 0;
+}
+ at end





More information about the cfe-commits mailing list