blob: 86f42d3abcab17aa7a60f74bccd622d90594deb2 [file] [log] [blame]
Ted Kremenekebcb57a2012-03-06 20:05:56 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2typedef _Bool BOOL;
3
4@interface NSNumber @end
5
6@interface NSNumber (NSNumberCreation)
7+ (NSNumber *)numberWithChar:(char)value;
8+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
9+ (NSNumber *)numberWithShort:(short)value;
10+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
11+ (NSNumber *)numberWithInt:(int)value;
12+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
13+ (NSNumber *)numberWithLong:(long)value;
14+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
15+ (NSNumber *)numberWithLongLong:(long long)value;
16+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
17+ (NSNumber *)numberWithFloat:(float)value;
18+ (NSNumber *)numberWithDouble:(double)value;
Jordy Rose3eda6fa2012-05-12 17:32:56 +000019+ (int)numberWithBool:(BOOL)value; // expected-note 2 {{method returns unexpected type 'int' (should be an object type)}}
Ted Kremenekebcb57a2012-03-06 20:05:56 +000020@end
21
Jordy Rose99446d92012-05-12 15:53:41 +000022@interface NSString
Jordy Rose3eda6fa2012-05-12 17:32:56 +000023+ (char)stringWithUTF8String:(const char *)value; // expected-note 2 {{method returns unexpected type 'char' (should be an object type)}}
Jordy Rose99446d92012-05-12 15:53:41 +000024@end
25
Ted Kremenekebcb57a2012-03-06 20:05:56 +000026@interface NSArray
27@end
28
29@interface NSArray (NSArrayCreation)
Jordy Rose3eda6fa2012-05-12 17:32:56 +000030+ (id)arrayWithObjects:(const int [])objects // expected-note 2 {{first parameter has unexpected type 'const int *' (should be 'const id *')}}
Ted Kremenekebcb57a2012-03-06 20:05:56 +000031 count:(unsigned long)cnt;
32@end
33
34@interface NSDictionary
35+ (id)dictionaryWithObjects:(const id [])objects
Jordy Rose3eda6fa2012-05-12 17:32:56 +000036 forKeys:(const int [])keys // expected-note 2 {{second parameter has unexpected type 'const int *' (should be 'const id *')}}
Ted Kremenekebcb57a2012-03-06 20:05:56 +000037 count:(unsigned long)cnt;
38@end
39
Jordy Rose3eda6fa2012-05-12 17:32:56 +000040// All tests are doubled to make sure that a bad method is not saved
41// and then used un-checked.
Ted Kremenekebcb57a2012-03-06 20:05:56 +000042void test_sig() {
43 (void)@__objc_yes; // expected-error{{literal construction method 'numberWithBool:' has incompatible signature}}
Jordy Rose3eda6fa2012-05-12 17:32:56 +000044 (void)@__objc_yes; // expected-error{{literal construction method 'numberWithBool:' has incompatible signature}}
Ted Kremenekebcb57a2012-03-06 20:05:56 +000045 id array = @[ @17 ]; // expected-error{{literal construction method 'arrayWithObjects:count:' has incompatible signature}}
Jordy Rose3eda6fa2012-05-12 17:32:56 +000046 id array2 = @[ @17 ]; // expected-error{{literal construction method 'arrayWithObjects:count:' has incompatible signature}}
Ted Kremenekebcb57a2012-03-06 20:05:56 +000047 id dict = @{ @"hello" : @17 }; // expected-error{{literal construction method 'dictionaryWithObjects:forKeys:count:' has incompatible signature}}
Jordy Rose3eda6fa2012-05-12 17:32:56 +000048 id dict2 = @{ @"hello" : @17 }; // expected-error{{literal construction method 'dictionaryWithObjects:forKeys:count:' has incompatible signature}}
Jordy Rose99446d92012-05-12 15:53:41 +000049 id str = @("hello"); // expected-error{{literal construction method 'stringWithUTF8String:' has incompatible signature}}
Jordy Rose3eda6fa2012-05-12 17:32:56 +000050 id str2 = @("hello"); // expected-error{{literal construction method 'stringWithUTF8String:' has incompatible signature}}
Ted Kremenekebcb57a2012-03-06 20:05:56 +000051}