Home | History | Annotate | Download | only in SemaObjC
      1 // RUN: %clang_cc1  -fsyntax-only -fblocks -triple x86_64-apple-darwin10 -verify %s
      2 // rdar://10111397
      3 
      4 #if __LP64__
      5 typedef unsigned long NSUInteger;
      6 typedef long NSInteger;
      7 #else
      8 typedef unsigned int NSUInteger;
      9 typedef int NSInteger;
     10 #endif
     11 
     12 @interface NSObject
     13 + (NSObject*)nsobject;
     14 @end
     15 
     16 @interface NSNumber : NSObject
     17 + (NSNumber *)numberWithChar:(char)value;
     18 + (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
     19 + (NSNumber *)numberWithShort:(short)value;
     20 + (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
     21 + (NSNumber *)numberWithInt:(int)value;
     22 + (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
     23 + (NSNumber *)numberWithLong:(long)value;
     24 + (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
     25 + (NSNumber *)numberWithLongLong:(long long)value;
     26 + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
     27 + (NSNumber *)numberWithFloat:(float)value;
     28 + (NSNumber *)numberWithInteger:(NSInteger)value ;
     29 + (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value ;
     30 @end
     31 
     32 // rdar://16417427
     33 int big = 1391126400;
     34 int thousand = 1000;
     35 int main() {
     36   NSNumber * N = @3.1415926535;  // expected-error {{declaration of 'numberWithDouble:' is missing in NSNumber class}}
     37   NSNumber *noNumber = @__objc_yes; // expected-error {{declaration of 'numberWithBool:' is missing in NSNumber class}}
     38   NSNumber * NInt = @1000;
     39   NSNumber * NLongDouble = @1000.0l; // expected-error{{'long double' is not a valid literal type for NSNumber}}
     40   id character = @ 'a';
     41 
     42   NSNumber *NNegativeInt = @-1000;
     43   NSNumber *NPositiveInt = @+1000;
     44   NSNumber *NNegativeFloat = @-1000.1f;
     45   NSNumber *NPositiveFloat = @+1000.1f;
     46 
     47   int five = 5;
     48   @-five; // expected-error{{@- must be followed by a number to form an NSNumber object}}
     49   @+five; // expected-error{{@+ must be followed by a number to form an NSNumber object}}
     50   NSNumber *av = @(1391126400000);
     51   NSNumber *bv = @(1391126400 * 1000); // expected-warning {{overflow in expression; result is -443003904 with type 'int'}}
     52   NSNumber *cv = @(big * thousand);
     53 }
     54 
     55 // Dictionary test
     56 @class NSDictionary;
     57 
     58 NSDictionary *err() {
     59   return @{@"name" : @"value"}; // expected-error {{declaration of 'dictionaryWithObjects:forKeys:count:' is missing in NSDictionary class}}
     60 }
     61 
     62 @interface NSDate : NSObject
     63 + (NSDate *) date;
     64 @end
     65 
     66 @protocol NSCopying
     67 - copy;
     68 @end
     69 
     70 @interface NSDictionary : NSObject
     71 + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(NSUInteger)cnt;
     72 @end
     73 
     74 @interface NSString<NSCopying>
     75 @end
     76 
     77 id NSUserName();
     78 
     79 int Int();
     80 
     81 NSDictionary * blocks() {
     82   return @{ @"task" : ^ { return 17; } };
     83 }
     84 
     85 NSDictionary * warn() {
     86   NSDictionary *dictionary = @{@"name" : NSUserName(),
     87                                @"date" : [NSDate date],
     88                                @"name2" : @"other",
     89                                NSObject.nsobject : @"nsobject" }; // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}}
     90   NSDictionary *dictionary2 = @{@"name" : Int()}; // expected-error {{collection element of type 'int' is not an Objective-C object}}
     91 
     92   NSObject *o;
     93   NSDictionary *dictionary3 = @{o : o, // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}}
     94                                @"date" : [NSDate date] };
     95   return dictionary3;
     96 }
     97 
     98 // rdar:// 11231426
     99 typedef float BOOL;
    100 
    101 BOOL radar11231426() {
    102         return __objc_yes;
    103 }
    104 
    105 id stringBoxingNoSuchMethod(const char *str) {
    106   return @(str); // expected-error {{declaration of 'stringWithUTF8String:' is missing in NSString class}}
    107 }
    108