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