blob: 356e26348e5270bc42a8ada521f666a041118ec7 [file] [log] [blame]
Ted Kremenekb3f75422012-03-06 20:06:06 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2// RUN: cp %s %t
3// RUN: not %clang_cc1 -fsyntax-only -fixit -x objective-c %t
4// RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -x objective-c %t
Jordan Rose9f63a452012-06-08 21:14:25 +00005// RUN: FileCheck -input-file=%t %s
Ted Kremenekb3f75422012-03-06 20:06:06 +00006
7typedef unsigned char BOOL;
8
Jordan Rose9f63a452012-06-08 21:14:25 +00009@interface NSObject
10- (BOOL)isEqual:(id)other;
11@end
Ted Kremenekb3f75422012-03-06 20:06:06 +000012
Jordan Rose9f63a452012-06-08 21:14:25 +000013@interface NSNumber : NSObject
Ted Kremenekb3f75422012-03-06 20:06:06 +000014+ (NSNumber *)numberWithChar:(char)value;
15+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
16+ (NSNumber *)numberWithShort:(short)value;
17+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
18+ (NSNumber *)numberWithInt:(int)value;
19+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
20+ (NSNumber *)numberWithLong:(long)value;
21+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
22+ (NSNumber *)numberWithLongLong:(long long)value;
23+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
24+ (NSNumber *)numberWithFloat:(float)value;
25+ (NSNumber *)numberWithDouble:(double)value;
26+ (NSNumber *)numberWithBool:(BOOL)value;
27@end
28
Jordan Rose9f63a452012-06-08 21:14:25 +000029@interface NSArray : NSObject
Ted Kremenekb3f75422012-03-06 20:06:06 +000030+ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
31@end
32
Jordan Rose9f63a452012-06-08 21:14:25 +000033@interface NSDictionary : NSObject
Ted Kremenekb3f75422012-03-06 20:06:06 +000034+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
35@end
36
Jordan Rose9f63a452012-06-08 21:14:25 +000037@interface NSString : NSObject
38@end
39
Ted Kremenekb3f75422012-03-06 20:06:06 +000040void fixes() {
41 id arr = @[
42 17, // expected-error{{numeric literal must be prefixed by '@' in a collection}}
43 'a', // expected-error{{character literal must be prefixed by '@'}}
44 "blah" // expected-error{{string literal must be prefixed by '@'}}
45 ];
46}
Jordan Rose9f63a452012-06-08 21:14:25 +000047
48void testComparisons(id obj) {
49 if (obj == @"abc") return; // expected-error{{direct comparison of a string literal is not allowed; use -isEqual: instead}}
50 if (obj != @"def") return; // expected-error{{direct comparison of a string literal is not allowed; use -isEqual: instead}}
51 if (@"ghi" == obj) return; // expected-error{{direct comparison of a string literal is not allowed; use -isEqual: instead}}
52
53 // CHECK: void testComparisons(id obj) {
54 // Make sure these three substitutions aren't matching the CHECK lines.
55 // CHECK-NEXT: if ([obj isEqual: @"abc"]) return;
56 // CHECK-NEXT: if (![obj isEqual: @"def"]) return;
57 // CHECK-NEXT: if ([@"ghi" isEqual: obj]) return;
58
59 if (@[] == obj) return; // expected-error{{direct comparison of an array literal is not allowed; use -isEqual: instead}}
60 if (@{} == obj) return; // expected-error{{direct comparison of a dictionary literal is not allowed; use -isEqual: instead}}
61 if (@12 == obj) return; // expected-error{{direct comparison of a numeric literal is not allowed; use -isEqual: instead}}
62 if (@1.0 == obj) return; // expected-error{{direct comparison of a numeric literal is not allowed; use -isEqual: instead}}
63 if (@__objc_yes == obj) return; // expected-error{{direct comparison of a numeric literal is not allowed; use -isEqual: instead}}
64 if (@(1+1) == obj) return; // expected-error{{direct comparison of a boxed expression is not allowed; use -isEqual: instead}}
65}
66