blob: f1019892ff3730edf1a767886a2b9217f3a8affd [file] [log] [blame]
Argyrios Kyrtzidis0d578a62012-05-15 19:17:49 +00001// RUN: rm -rf %t
Argyrios Kyrtzidis811ee0e2012-05-24 17:49:22 +00002// RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c++ -verify
Argyrios Kyrtzidis0d578a62012-05-15 19:17:49 +00003// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
4// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c++ %s.result
5
6#define YES __objc_yes
7#define NO __objc_no
8
9typedef long NSInteger;
10typedef unsigned long NSUInteger;
11typedef signed char BOOL;
12#define nil ((void*) 0)
13
14#define INT_MIN (-__INT_MAX__ -1)
15
16@interface NSObject
17+ (id)alloc;
18@end
19
20@interface NSNumber : NSObject
21@end
22
23@interface NSNumber (NSNumberCreation)
24- (id)initWithChar:(char)value;
25- (id)initWithUnsignedChar:(unsigned char)value;
26- (id)initWithShort:(short)value;
27- (id)initWithUnsignedShort:(unsigned short)value;
28- (id)initWithInt:(int)value;
29- (id)initWithUnsignedInt:(unsigned int)value;
30- (id)initWithLong:(long)value;
31- (id)initWithUnsignedLong:(unsigned long)value;
32- (id)initWithLongLong:(long long)value;
33- (id)initWithUnsignedLongLong:(unsigned long long)value;
34- (id)initWithFloat:(float)value;
35- (id)initWithDouble:(double)value;
36- (id)initWithBool:(BOOL)value;
37- (id)initWithInteger:(NSInteger)value;
38- (id)initWithUnsignedInteger:(NSUInteger)value;
39
40+ (NSNumber *)numberWithChar:(char)value;
41+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
42+ (NSNumber *)numberWithShort:(short)value;
43+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
44+ (NSNumber *)numberWithInt:(int)value;
45+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
46+ (NSNumber *)numberWithLong:(long)value;
47+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
48+ (NSNumber *)numberWithLongLong:(long long)value;
49+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
50+ (NSNumber *)numberWithFloat:(float)value;
51+ (NSNumber *)numberWithDouble:(double)value;
52+ (NSNumber *)numberWithBool:(BOOL)value;
53+ (NSNumber *)numberWithInteger:(NSInteger)value;
54+ (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value;
55@end
56
Argyrios Kyrtzidis7fe103c2012-05-15 22:22:10 +000057enum {
58 NSASCIIStringEncoding = 1,
59 NSUTF8StringEncoding = 4,
60 NSUnicodeStringEncoding = 10
61};
62typedef NSUInteger NSStringEncoding;
63
64@interface NSString : NSObject
65@end
66
67@interface NSString (NSStringExtensionMethods)
68+ (id)stringWithUTF8String:(const char *)nullTerminatedCString;
69+ (id)stringWithCString:(const char *)cString encoding:(NSStringEncoding)enc;
70+ (id)stringWithCString:(const char *)bytes;
71@end
72
Argyrios Kyrtzidis0d578a62012-05-15 19:17:49 +000073enum MyEnm {
74 ME_foo
75};
76
77void foo() {
78 @INT_MIN;
79 bool cppb;
80 @(cppb);
81 MyEnm myenum;
82 @(myenum);
83 @(ME_foo);
Argyrios Kyrtzidis8b9fcd72012-06-20 01:28:32 +000084 [NSNumber numberWithDouble:cppb]; // expected-warning {{converting to boxing syntax requires casting 'bool' to 'double'}}
Argyrios Kyrtzidis0d578a62012-05-15 19:17:49 +000085}
Argyrios Kyrtzidis7fe103c2012-05-15 22:22:10 +000086
87void boxString() {
88 NSString *s = @"box";
89 const char *cstr1;
90 char *cstr2;
91 s = @(cstr1);
92 s = @(cstr2);
93 s = @(cstr1);
94 s = @(cstr1);
95 s = [NSString stringWithCString:cstr1 encoding: NSUnicodeStringEncoding];
96 NSStringEncoding encode;
97 s = [NSString stringWithCString:cstr1 encoding:encode];
98 s = @(cstr1);
Argyrios Kyrtzidis07736592012-05-16 00:21:21 +000099
100 static const char strarr[] = "coolbox";
101 s = @(strarr);
Argyrios Kyrtzidis7fe103c2012-05-15 22:22:10 +0000102}