1 // RUN: %clang_cc1 -E %s -o %t.mm 2 // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s 3 // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o %t-rw.cpp 4 // RUN: %clang_cc1 -fsyntax-only -Werror -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -U__declspec -D"__declspec(X)=" %t-rw.cpp -Wno-attributes 5 6 extern char *strdup(const char *str); 7 extern "C" void *sel_registerName(const char *); 8 9 typedef signed char BOOL; 10 typedef long NSInteger; 11 typedef unsigned long NSUInteger; 12 13 #if __has_feature(objc_bool) 14 #define YES __objc_yes 15 #define NO __objc_no 16 #else 17 #define YES ((BOOL)1) 18 #define NO ((BOOL)0) 19 #endif 20 21 @interface NSNumber 22 + (NSNumber *)numberWithChar:(char)value; 23 + (NSNumber *)numberWithUnsignedChar:(unsigned char)value; 24 + (NSNumber *)numberWithShort:(short)value; 25 + (NSNumber *)numberWithUnsignedShort:(unsigned short)value; 26 + (NSNumber *)numberWithInt:(int)value; 27 + (NSNumber *)numberWithUnsignedInt:(unsigned int)value; 28 + (NSNumber *)numberWithLong:(long)value; 29 + (NSNumber *)numberWithUnsignedLong:(unsigned long)value; 30 + (NSNumber *)numberWithLongLong:(long long)value; 31 + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; 32 + (NSNumber *)numberWithFloat:(float)value; 33 + (NSNumber *)numberWithDouble:(double)value; 34 + (NSNumber *)numberWithBool:(BOOL)value; 35 + (NSNumber *)numberWithInteger:(NSInteger)value ; 36 + (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value ; 37 @end 38 39 @interface NSString 40 + (id)stringWithUTF8String:(const char *)str; 41 @end 42 43 int main(int argc, const char *argv[]) { 44 // character. 45 NSNumber *theLetterZ = @('Z'); // equivalent to [NSNumber numberWithChar:('Z')] 46 47 // integral. 48 NSNumber *fortyTwo = @(42); // equivalent to [NSNumber numberWithInt:(42)] 49 NSNumber *fortyTwoUnsigned = @(42U); // equivalent to [NSNumber numberWithUnsignedInt:(42U)] 50 NSNumber *fortyTwoLong = @(42L); // equivalent to [NSNumber numberWithLong:(42L)] 51 NSNumber *fortyTwoLongLong = @(42LL); // equivalent to [NSNumber numberWithLongLong:(42LL)] 52 53 // floating point. 54 NSNumber *piFloat = @(3.141592654F); // equivalent to [NSNumber numberWithFloat:(3.141592654F)] 55 NSNumber *piDouble = @(3.1415926535); // equivalent to [NSNumber numberWithDouble:(3.1415926535)] 56 57 BOOL b; 58 NSNumber *nsb = @(b); 59 60 // Strings. 61 NSString *duplicateString = @(strdup("Hello")); 62 } 63 64 // CHECK: NSNumber *theLetterZ = ((NSNumber *(*)(Class, SEL, char))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithChar:"), ('Z')); 65 // CHECK: NSNumber *fortyTwo = ((NSNumber *(*)(Class, SEL, int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithInt:"), (42)); 66 // CHECK: NSNumber *fortyTwoUnsigned = ((NSNumber *(*)(Class, SEL, unsigned int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithUnsignedInt:"), (42U)); 67 // CHECK: NSNumber *fortyTwoLong = ((NSNumber *(*)(Class, SEL, long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLong:"), (42L)); 68 // CHECK: NSNumber *fortyTwoLongLong = ((NSNumber *(*)(Class, SEL, long long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLongLong:"), (42LL)); 69 // CHECK: NSNumber *piFloat = ((NSNumber *(*)(Class, SEL, float))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithFloat:"), (3.14159274F)); 70 // CHECK: NSNumber *piDouble = ((NSNumber *(*)(Class, SEL, double))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithDouble:"), (3.1415926535000001)); 71 // CHECK: NSNumber *nsb = ((NSNumber *(*)(Class, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)(b)); 72 // CHECK: NSString *duplicateString = ((NSString *(*)(Class, SEL, const char *))(void *)objc_msgSend)(objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), (const char *)(strdup("Hello"))); 73