1// RUN: rm -rf %t 2// RUN: %clang_cc1 -fobjc-arc -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c++ -verify 3// 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 57enum { 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- (instancetype)initWithUTF8String:(const char *)nullTerminatedCString; 72@end 73 74enum MyEnm { 75 ME_foo 76}; 77 78void foo() { 79 [NSNumber numberWithInt:INT_MIN]; 80 bool cppb; 81 [NSNumber numberWithBool:cppb]; 82 MyEnm myenum; 83 [NSNumber numberWithInteger:myenum]; 84 [NSNumber numberWithInteger:ME_foo]; 85 [NSNumber numberWithDouble:cppb]; // expected-warning {{converting to boxing syntax requires casting 'bool' to 'double'}} 86} 87 88void boxString() { 89 NSString *s = [NSString stringWithUTF8String:"box"]; 90 const char *cstr1; 91 char *cstr2; 92 s = [NSString stringWithUTF8String:cstr1]; 93 s = [NSString stringWithUTF8String:cstr2]; 94 s = [NSString stringWithCString:cstr1 encoding:NSASCIIStringEncoding]; 95 s = [NSString stringWithCString:cstr1 encoding:NSUTF8StringEncoding]; 96 s = [NSString stringWithCString:cstr1 encoding: NSUnicodeStringEncoding]; 97 NSStringEncoding encode; 98 s = [NSString stringWithCString:cstr1 encoding:encode]; 99 s = [NSString stringWithCString:cstr1]; 100 101 static const char strarr[] = "coolbox"; 102 s = [NSString stringWithUTF8String:strarr]; 103 // rdar://18080352 104 const char *utf8Bytes = "blah"; 105 NSString *string1 = [NSString stringWithUTF8String:utf8Bytes]; 106 NSString *string2 = [[NSString alloc] initWithUTF8String:utf8Bytes]; 107} 108