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