xref: /aosp_15_r20/external/clang/test/SemaObjC/cocoa-api-usage.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc %s -fsyntax-only -Wobjc-cocoa-api -verify
2*67e74705SXin Li// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -x objective-c %s.fixed -fsyntax-only
3*67e74705SXin Li// RUN: cp %s %t.m
4*67e74705SXin Li// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc %t.m -fixit -Wobjc-cocoa-api
5*67e74705SXin Li// RUN: diff %s.fixed %t.m
6*67e74705SXin Li
7*67e74705SXin Litypedef signed char BOOL;
8*67e74705SXin Li#define nil ((void*) 0)
9*67e74705SXin Li
10*67e74705SXin Li@interface NSObject
11*67e74705SXin Li+ (id)alloc;
12*67e74705SXin Li@end
13*67e74705SXin Li
14*67e74705SXin Li@interface NSString : NSObject
15*67e74705SXin Li+ (id)stringWithString:(NSString *)string;
16*67e74705SXin Li- (id)initWithString:(NSString *)aString;
17*67e74705SXin Li@end
18*67e74705SXin Li
19*67e74705SXin Li@interface NSArray : NSObject
20*67e74705SXin Li- (id)objectAtIndex:(unsigned long)index;
21*67e74705SXin Li- (id)objectAtIndexedSubscript:(int)index;
22*67e74705SXin Li@end
23*67e74705SXin Li
24*67e74705SXin Li@interface NSArray (NSArrayCreation)
25*67e74705SXin Li+ (id)array;
26*67e74705SXin Li+ (id)arrayWithObject:(id)anObject;
27*67e74705SXin Li+ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
28*67e74705SXin Li+ (id)arrayWithObjects:(id)firstObj, ...;
29*67e74705SXin Li+ (id)arrayWithArray:(NSArray *)array;
30*67e74705SXin Li
31*67e74705SXin Li- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt;
32*67e74705SXin Li- (id)initWithObjects:(id)firstObj, ...;
33*67e74705SXin Li- (id)initWithArray:(NSArray *)array;
34*67e74705SXin Li
35*67e74705SXin Li- (id)objectAtIndex:(unsigned long)index;
36*67e74705SXin Li@end
37*67e74705SXin Li
38*67e74705SXin Li@interface NSMutableArray : NSArray
39*67e74705SXin Li- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject;
40*67e74705SXin Li- (void)setObject:(id)object atIndexedSubscript:(int)index;
41*67e74705SXin Li@end
42*67e74705SXin Li
43*67e74705SXin Li@interface NSDictionary : NSObject
44*67e74705SXin Li- (id)objectForKeyedSubscript:(id)key;
45*67e74705SXin Li@end
46*67e74705SXin Li
47*67e74705SXin Li@interface NSDictionary (NSDictionaryCreation)
48*67e74705SXin Li+ (id)dictionary;
49*67e74705SXin Li+ (id)dictionaryWithObject:(id)object forKey:(id)key;
50*67e74705SXin Li+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
51*67e74705SXin Li+ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...;
52*67e74705SXin Li+ (id)dictionaryWithDictionary:(NSDictionary *)dict;
53*67e74705SXin Li+ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
54*67e74705SXin Li
55*67e74705SXin Li- (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
56*67e74705SXin Li- (id)initWithObjectsAndKeys:(id)firstObject, ...;
57*67e74705SXin Li- (id)initWithDictionary:(NSDictionary *)otherDictionary;
58*67e74705SXin Li- (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
59*67e74705SXin Li
60*67e74705SXin Li- (id)objectForKey:(id)aKey;
61*67e74705SXin Li@end
62*67e74705SXin Li
63*67e74705SXin Li@interface NSMutableDictionary : NSDictionary
64*67e74705SXin Li- (void)setObject:(id)anObject forKey:(id)aKey;
65*67e74705SXin Li- (void)setObject:(id)object forKeyedSubscript:(id)key;
66*67e74705SXin Li@end
67*67e74705SXin Li
68*67e74705SXin Li@interface NSNumber : NSObject
69*67e74705SXin Li@end
70*67e74705SXin Li
71*67e74705SXin Li@interface NSNumber (NSNumberCreation)
72*67e74705SXin Li+ (NSNumber *)numberWithInt:(int)value;
73*67e74705SXin Li@end
74*67e74705SXin Li
75*67e74705SXin Li#define M(x) (x)
76*67e74705SXin Li#define PAIR(x) @#x, [NSNumber numberWithInt:(x)]
77*67e74705SXin Li#define TWO(x) ((x), (x))
78*67e74705SXin Li
79*67e74705SXin Livoid foo() {
80*67e74705SXin Li  NSString *str = M([NSString stringWithString:@"foo"]); // expected-warning {{redundant}}
81*67e74705SXin Li  str = [[NSString alloc] initWithString:@"foo"]; // expected-warning {{redundant}}
82*67e74705SXin Li  NSArray *arr = [NSArray arrayWithArray:@[str]]; // expected-warning {{redundant}}
83*67e74705SXin Li  NSDictionary *dict = [NSDictionary dictionaryWithDictionary:@{str: arr}]; // expected-warning {{redundant}}
84*67e74705SXin Li}
85