xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjC/objc-literal-sig.m (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuctypedef _Bool BOOL;
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc@interface NSNumber @end
5*f4a2713aSLionel Sambuc
6*f4a2713aSLionel Sambuc@interface NSNumber (NSNumberCreation)
7*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithChar:(char)value;
8*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
9*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithShort:(short)value;
10*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
11*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithInt:(int)value;
12*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
13*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithLong:(long)value;
14*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
15*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithLongLong:(long long)value;
16*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
17*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithFloat:(float)value;
18*f4a2713aSLionel Sambuc+ (NSNumber *)numberWithDouble:(double)value;
19*f4a2713aSLionel Sambuc+ (int)numberWithBool:(BOOL)value; // expected-note 2 {{method returns unexpected type 'int' (should be an object type)}}
20*f4a2713aSLionel Sambuc@end
21*f4a2713aSLionel Sambuc
22*f4a2713aSLionel Sambuc@interface NSString
23*f4a2713aSLionel Sambuc+ (char)stringWithUTF8String:(const char *)value; // expected-note 2 {{method returns unexpected type 'char' (should be an object type)}}
24*f4a2713aSLionel Sambuc@end
25*f4a2713aSLionel Sambuc
26*f4a2713aSLionel Sambuc@interface NSArray
27*f4a2713aSLionel Sambuc@end
28*f4a2713aSLionel Sambuc
29*f4a2713aSLionel Sambuc@interface NSArray (NSArrayCreation)
30*f4a2713aSLionel Sambuc+ (id)arrayWithObjects:(const int [])objects // expected-note 2 {{first parameter has unexpected type 'const int *' (should be 'const id *')}}
31*f4a2713aSLionel Sambuc                 count:(unsigned long)cnt;
32*f4a2713aSLionel Sambuc@end
33*f4a2713aSLionel Sambuc
34*f4a2713aSLionel Sambuc@interface NSDictionary
35*f4a2713aSLionel Sambuc+ (id)dictionaryWithObjects:(const id [])objects
36*f4a2713aSLionel Sambuc                    forKeys:(const int [])keys // expected-note 2 {{second parameter has unexpected type 'const int *' (should be 'const id *')}}
37*f4a2713aSLionel Sambuc                      count:(unsigned long)cnt;
38*f4a2713aSLionel Sambuc@end
39*f4a2713aSLionel Sambuc
40*f4a2713aSLionel Sambuc// All tests are doubled to make sure that a bad method is not saved
41*f4a2713aSLionel Sambuc// and then used un-checked.
42*f4a2713aSLionel Sambucvoid test_sig() {
43*f4a2713aSLionel Sambuc  (void)@__objc_yes; // expected-error{{literal construction method 'numberWithBool:' has incompatible signature}}
44*f4a2713aSLionel Sambuc  (void)@__objc_yes; // expected-error{{literal construction method 'numberWithBool:' has incompatible signature}}
45*f4a2713aSLionel Sambuc  id array = @[ @17 ]; // expected-error{{literal construction method 'arrayWithObjects:count:' has incompatible signature}}
46*f4a2713aSLionel Sambuc  id array2 = @[ @17 ]; // expected-error{{literal construction method 'arrayWithObjects:count:' has incompatible signature}}
47*f4a2713aSLionel Sambuc  id dict = @{ @"hello" : @17 }; // expected-error{{literal construction method 'dictionaryWithObjects:forKeys:count:' has incompatible signature}}
48*f4a2713aSLionel Sambuc  id dict2 = @{ @"hello" : @17 }; // expected-error{{literal construction method 'dictionaryWithObjects:forKeys:count:' has incompatible signature}}
49*f4a2713aSLionel Sambuc  id str = @("hello"); // expected-error{{literal construction method 'stringWithUTF8String:' has incompatible signature}}
50*f4a2713aSLionel Sambuc  id str2 = @("hello"); // expected-error{{literal construction method 'stringWithUTF8String:' has incompatible signature}}
51*f4a2713aSLionel Sambuc}
52