Ted Kremenek | b3f7542 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 1 | // 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 Rose | 9f63a45 | 2012-06-08 21:14:25 +0000 | [diff] [blame^] | 5 | // RUN: FileCheck -input-file=%t %s |
Ted Kremenek | b3f7542 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 6 | |
| 7 | typedef unsigned char BOOL; |
| 8 | |
Jordan Rose | 9f63a45 | 2012-06-08 21:14:25 +0000 | [diff] [blame^] | 9 | @interface NSObject |
| 10 | - (BOOL)isEqual:(id)other; |
| 11 | @end |
Ted Kremenek | b3f7542 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 12 | |
Jordan Rose | 9f63a45 | 2012-06-08 21:14:25 +0000 | [diff] [blame^] | 13 | @interface NSNumber : NSObject |
Ted Kremenek | b3f7542 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 14 | + (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 Rose | 9f63a45 | 2012-06-08 21:14:25 +0000 | [diff] [blame^] | 29 | @interface NSArray : NSObject |
Ted Kremenek | b3f7542 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 30 | + (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; |
| 31 | @end |
| 32 | |
Jordan Rose | 9f63a45 | 2012-06-08 21:14:25 +0000 | [diff] [blame^] | 33 | @interface NSDictionary : NSObject |
Ted Kremenek | b3f7542 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 34 | + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt; |
| 35 | @end |
| 36 | |
Jordan Rose | 9f63a45 | 2012-06-08 21:14:25 +0000 | [diff] [blame^] | 37 | @interface NSString : NSObject |
| 38 | @end |
| 39 | |
Ted Kremenek | b3f7542 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 40 | void 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 Rose | 9f63a45 | 2012-06-08 21:14:25 +0000 | [diff] [blame^] | 47 | |
| 48 | void 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 | |