Home | History | Annotate | Download | only in ARCMT
      1 // RUN: rm -rf %t
      2 // RUN: %clang_cc1 -objcmt-migrate-instancetype -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11
      3 // RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
      4 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result
      5 
      6 typedef signed char BOOL;
      7 #define nil ((void*) 0)
      8 
      9 @interface NSObject
     10 + (id)alloc;
     11 @end
     12 
     13 @interface NSString : NSObject
     14 + (id)stringWithString:(NSString *)string;
     15 - (id)initWithString:(NSString *)aString;
     16 @end
     17 
     18 @implementation NSString : NSObject
     19 + (id)stringWithString:(NSString *)string { return 0; };
     20 - (instancetype)initWithString:(NSString *)aString { return 0; };
     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 + 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 @implementation NSArray (NSArrayCreation)
     43 + (id)array { return 0; }
     44 + (id)arrayWithObject:(id)anObject {
     45   return anObject;
     46 }
     47 + (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt { return 0; }
     48 + (id)arrayWithObjects:(id)firstObj, ... {
     49   return 0; }
     50 + arrayWithArray:(NSArray *)array {
     51   return 0;
     52 }
     53 
     54 - (id)initWithObjects:(const id [])objects count:(unsigned long)cnt { return 0; }
     55 - (id)initWithObjects:(id)firstObj, ... { return 0; }
     56 - (id)initWithArray:(NSArray *)array { return 0; }
     57 
     58 - (id)objectAtIndex:(unsigned long)index { return 0; }
     59 @end
     60 
     61 @interface NSMutableArray : NSArray
     62 - (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject;
     63 - (void)setObject:(id)object atIndexedSubscript:(int)index;
     64 @end
     65 
     66 @interface NSDictionary : NSObject
     67 - (id)objectForKeyedSubscript:(id)key;
     68 @end
     69 
     70 @interface NSDictionary (NSDictionaryCreation)
     71 + (id)dictionary;
     72 + (id)dictionaryWithObject:(id)object forKey:(id)key;
     73 + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
     74 + dictionaryWithObjectsAndKeys:(id)firstObject, ...;
     75 + (id)dictionaryWithDictionary:(NSDictionary *)dict;
     76 + (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
     77 
     78 - (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
     79 - (id)initWithObjectsAndKeys:(id)firstObject, ...;
     80 - (id)initWithDictionary:(NSDictionary *)otherDictionary;
     81 - (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
     82 
     83 - (id)objectForKey:(id)aKey;
     84 @end
     85 
     86 @interface NSMutableDictionary : NSDictionary
     87 - (void)setObject:(id)anObject forKey:(id)aKey;
     88 - (void)setObject:(id)object forKeyedSubscript:(id)key;
     89 @end
     90 
     91 @interface NSNumber : NSObject
     92 @end
     93 
     94 @interface NSNumber (NSNumberCreation)
     95 + (NSNumber *)numberWithInt:(int)value;
     96 @end
     97 
     98 @implementation NSNumber (NSNumberCreation)
     99 + (NSNumber *)numberWithInt:(int)value { return 0; }
    100 @end
    101 
    102 #define M(x) (x)
    103 #define PAIR(x) @#x, [NSNumber numberWithInt:(x)]
    104 #define TWO(x) ((x), (x))
    105 
    106 void foo() {
    107   NSString *str = M([NSString stringWithString:@"foo"]); // expected-warning {{redundant}}
    108   str = [[NSString alloc] initWithString:@"foo"]; // expected-warning {{redundant}}
    109   NSArray *arr = [NSArray arrayWithArray:@[str]]; // expected-warning {{redundant}}
    110   NSDictionary *dict = [NSDictionary dictionaryWithDictionary:@{str: arr}]; // expected-warning {{redundant}}
    111 }
    112