• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1  -fsyntax-only -fblocks -verify %s
2// rdar://10111397
3
4#if __LP64__
5typedef unsigned long NSUInteger;
6#else
7typedef 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
20int 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
40NSDictionary *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
59id NSUserName();
60
61int Int();
62
63NSDictionary * blocks() {
64  return @{ @"task" : ^ { return 17; } };
65}
66
67NSDictionary * 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}
79
80// rdar:// 11231426
81typedef float BOOL;
82
83BOOL radar11231426() {
84        return __objc_yes;
85}
86