Ted Kremenek | ebcb57a | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s |
| 2 | // rdar://10111397 |
| 3 | |
| 4 | #if __LP64__ |
| 5 | typedef unsigned long NSUInteger; |
| 6 | #else |
| 7 | typedef unsigned int NSUInteger; |
| 8 | #endif |
| 9 | |
| 10 | @interface NSObject |
| 11 | + (NSObject*)nsobject; |
| 12 | @end |
| 13 | |
| 14 | @interface NSNumber : NSObject |
| 15 | + (NSNumber *)numberWithChar:(char)value; |
| 16 | + (NSNumber *)numberWithInt:(int)value; |
| 17 | + (NSNumber *)numberWithFloat:(float)value; |
| 18 | @end |
| 19 | |
| 20 | int main() { |
| 21 | NSNumber * N = @3.1415926535; // expected-error {{declaration of 'numberWithDouble:' is missing in NSNumber class}} |
| 22 | NSNumber *noNumber = @__objc_yes; // expected-error {{declaration of 'numberWithBool:' is missing in NSNumber class}} |
| 23 | NSNumber * NInt = @1000; |
| 24 | NSNumber * NLongDouble = @1000.0l; // expected-error{{'long double' is not a valid literal type for NSNumber}} |
| 25 | id character = @ 'a'; |
| 26 | |
| 27 | NSNumber *NNegativeInt = @-1000; |
| 28 | NSNumber *NPositiveInt = @+1000; |
| 29 | NSNumber *NNegativeFloat = @-1000.1f; |
| 30 | NSNumber *NPositiveFloat = @+1000.1f; |
| 31 | |
| 32 | int five = 5; |
| 33 | @-five; // expected-error{{@- must be followed by a number to form an NSNumber object}} |
| 34 | @+five; // expected-error{{@+ must be followed by a number to form an NSNumber object}} |
| 35 | } |
| 36 | |
| 37 | // Dictionary test |
| 38 | @class NSDictionary; |
| 39 | |
| 40 | NSDictionary *err() { |
| 41 | return @{@"name" : @"value"}; // expected-error {{declaration of 'dictionaryWithObjects:forKeys:count:' is missing in NSDictionary class}} |
| 42 | } |
| 43 | |
| 44 | @interface NSDate : NSObject |
| 45 | + (NSDate *) date; |
| 46 | @end |
| 47 | |
| 48 | @protocol NSCopying |
| 49 | - copy; |
| 50 | @end |
| 51 | |
| 52 | @interface NSDictionary : NSObject |
| 53 | + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(NSUInteger)cnt; |
| 54 | @end |
| 55 | |
| 56 | @interface NSString<NSCopying> |
| 57 | @end |
| 58 | |
| 59 | id NSUserName(); |
| 60 | |
| 61 | int Int(); |
| 62 | |
| 63 | NSDictionary * blocks() { |
| 64 | return @{ @"task" : ^ { return 17; } }; |
| 65 | } |
| 66 | |
| 67 | NSDictionary * warn() { |
| 68 | NSDictionary *dictionary = @{@"name" : NSUserName(), |
| 69 | @"date" : [NSDate date], |
| 70 | @"name2" : @"other", |
| 71 | NSObject.nsobject : @"nsobject" }; // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}} |
| 72 | NSDictionary *dictionary2 = @{@"name" : Int()}; // expected-error {{collection element of type 'int' is not an Objective-C object}} |
| 73 | |
| 74 | NSObject *o; |
| 75 | NSDictionary *dictionary3 = @{o : o, // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}} |
| 76 | @"date" : [NSDate date] }; |
| 77 | return dictionary3; |
| 78 | } |
Fariborz Jahanian | 262acda | 2012-04-12 21:24:56 +0000 | [diff] [blame] | 79 | |
| 80 | // rdar:// 11231426 |
Fariborz Jahanian | 93a4994 | 2012-04-16 21:03:30 +0000 | [diff] [blame] | 81 | typedef float BOOL; |
Fariborz Jahanian | 262acda | 2012-04-12 21:24:56 +0000 | [diff] [blame] | 82 | |
| 83 | BOOL radar11231426() { |
Fariborz Jahanian | 93a4994 | 2012-04-16 21:03:30 +0000 | [diff] [blame] | 84 | return __objc_yes; |
Fariborz Jahanian | 262acda | 2012-04-12 21:24:56 +0000 | [diff] [blame] | 85 | } |
Jordy Rose | 99446d9 | 2012-05-12 15:53:41 +0000 | [diff] [blame] | 86 | |
| 87 | id stringBoxingNoSuchMethod(const char *str) { |
| 88 | return @(str); // expected-error {{declaration of 'stringWithUTF8String:' is missing in NSString class}} |
| 89 | } |