summaryrefslogtreecommitdiff
path: root/clang/test/SemaObjC/objc-literal-nsnumber.m
blob: 6635bea72e7f3ed00b3f98f18ad7856f7f3c84fb (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// RUN: %clang_cc1  -fsyntax-only -fblocks -verify %s
// rdar://10111397

#if __LP64__
typedef unsigned long NSUInteger;
#else
typedef unsigned int NSUInteger;
#endif

@interface NSObject
+ (NSObject*)nsobject;
@end

@interface NSNumber : NSObject
+ (NSNumber *)numberWithChar:(char)value;
+ (NSNumber *)numberWithInt:(int)value;
+ (NSNumber *)numberWithFloat:(float)value;
@end

int main() {
  NSNumber * N = @3.1415926535;  // expected-error {{declaration of 'numberWithDouble:' is missing in NSNumber class}}
  NSNumber *noNumber = @__objc_yes; // expected-error {{declaration of 'numberWithBool:' is missing in NSNumber class}}
  NSNumber * NInt = @1000;
  NSNumber * NLongDouble = @1000.0l; // expected-error{{'long double' is not a valid literal type for NSNumber}}
  id character = @ 'a';

  NSNumber *NNegativeInt = @-1000;
  NSNumber *NPositiveInt = @+1000;
  NSNumber *NNegativeFloat = @-1000.1f;
  NSNumber *NPositiveFloat = @+1000.1f;

  int five = 5;
  @-five; // expected-error{{@- must be followed by a number to form an NSNumber object}}
  @+five; // expected-error{{@+ must be followed by a number to form an NSNumber object}}
}

// Dictionary test
@class NSDictionary;

NSDictionary *err() {
  return @{@"name" : @"value"}; // expected-error {{declaration of 'dictionaryWithObjects:forKeys:count:' is missing in NSDictionary class}}
}

@interface NSDate : NSObject
+ (NSDate *) date;
@end

@protocol NSCopying
- copy;
@end

@interface NSDictionary : NSObject
+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(NSUInteger)cnt;
@end

@interface NSString<NSCopying>
@end

id NSUserName();

int Int();

NSDictionary * blocks() {
  return @{ @"task" : ^ { return 17; } };
}

NSDictionary * warn() {
  NSDictionary *dictionary = @{@"name" : NSUserName(),
                               @"date" : [NSDate date],
                               @"name2" : @"other",
                               NSObject.nsobject : @"nsobject" }; // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}}
  NSDictionary *dictionary2 = @{@"name" : Int()}; // expected-error {{collection element of type 'int' is not an Objective-C object}}

  NSObject *o;
  NSDictionary *dictionary3 = @{o : o, // expected-warning{{passing 'NSObject *' to parameter of incompatible type 'const id<NSCopying>'}}
                               @"date" : [NSDate date] };
  return dictionary3;
}

// rdar:// 11231426
typedef float BOOL;

BOOL radar11231426() {
        return __objc_yes;
}