]> granicus.if.org Git - clang/commitdiff
Add test case for NSString format-string checking.
authorTed Kremenek <kremenek@apple.com>
Mon, 16 Jun 2008 18:01:05 +0000 (18:01 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 16 Jun 2008 18:01:05 +0000 (18:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52337 91177308-0d34-0410-b5e6-96231b3b80d8

test/Sema/format-strings-objc.m [new file with mode: 0644]

diff --git a/test/Sema/format-strings-objc.m b/test/Sema/format-strings-objc.m
new file mode 100644 (file)
index 0000000..bdf1208
--- /dev/null
@@ -0,0 +1,36 @@
+// RUN: clang -fsyntax-only -verify %s
+
+//===----------------------------------------------------------------------===//
+// The following code is reduced using delta-debugging from
+// Foundation.h (Mac OS X).
+//
+// It includes the basic definitions for the test cases below.
+// Not including Foundation.h directly makes this test case both svelt and
+// portable to non-Mac platforms.
+//===----------------------------------------------------------------------===//
+
+typedef signed char BOOL;
+typedef unsigned int NSUInteger;
+@class NSString, Protocol;
+extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
+typedef struct _NSZone NSZone;
+@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+@protocol NSObject  - (BOOL)isEqual:(id)object; @end
+@protocol NSCopying  - (id)copyWithZone:(NSZone *)zone; @end
+@protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone; @end
+@protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder; @end
+@interface NSObject <NSObject> {} @end
+typedef float CGFloat;
+@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>    - (NSUInteger)length; @end
+@interface NSSimpleCString : NSString {} @end
+@interface NSConstantString : NSSimpleCString @end
+extern void *_NSConstantStringClassReference;
+
+//===----------------------------------------------------------------------===//
+// Test cases.
+//===----------------------------------------------------------------------===//
+
+void check_nslog(unsigned k) {
+  NSLog(@"%d%%", k); // no-warning
+  NSLog(@"%s%lb%d", "unix", 10,20); // expected-warning {{lid conversion '%lb'}}
+}