blob: 42c21705b50b3fb89e42bcfd0185d9f40fef0d85 [file] [log] [blame]
Ted Kremenekdf220832008-06-16 18:01:05 +00001// RUN: clang -fsyntax-only -verify %s
2
3//===----------------------------------------------------------------------===//
4// The following code is reduced using delta-debugging from
5// Foundation.h (Mac OS X).
6//
7// It includes the basic definitions for the test cases below.
8// Not including Foundation.h directly makes this test case both svelt and
9// portable to non-Mac platforms.
10//===----------------------------------------------------------------------===//
11
12typedef signed char BOOL;
13typedef unsigned int NSUInteger;
14@class NSString, Protocol;
15extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
16typedef struct _NSZone NSZone;
17@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
18@protocol NSObject - (BOOL)isEqual:(id)object; @end
19@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
20@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end
21@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end
22@interface NSObject <NSObject> {} @end
23typedef float CGFloat;
24@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> - (NSUInteger)length; @end
25@interface NSSimpleCString : NSString {} @end
26@interface NSConstantString : NSSimpleCString @end
27extern void *_NSConstantStringClassReference;
28
Daniel Dunbar085e8f72008-09-26 03:32:58 +000029typedef const struct __CFString * CFStringRef;
30extern void CFStringCreateWithFormat(CFStringRef format, ...) __attribute__((format(CFString, 1, 2)));
31
Ted Kremenekdf220832008-06-16 18:01:05 +000032//===----------------------------------------------------------------------===//
33// Test cases.
34//===----------------------------------------------------------------------===//
35
36void check_nslog(unsigned k) {
37 NSLog(@"%d%%", k); // no-warning
38 NSLog(@"%s%lb%d", "unix", 10,20); // expected-warning {{lid conversion '%lb'}}
39}
Daniel Dunbar085e8f72008-09-26 03:32:58 +000040
41// Check type validation
42extern void NSLog2(int format, ...) __attribute__((format(__NSString__, 1, 2))); // expected-error {{format argument not an NSString}}
43extern void CFStringCreateWithFormat2(int *format, ...) __attribute__((format(CFString, 1, 2))); // expected-error {{format argument not a CFString}}