61 lines · plain
1// RUN: %clang_cc1 -fsyntax-only -verify %s2// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify %s3 4#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_645typedef unsigned long NSUInteger;6#else7typedef unsigned int NSUInteger;8#endif9 10@protocol NSObject11@end12 13@protocol NSCopying14@end15 16__attribute__((objc_root_class))17@interface NSObject <NSObject>18@end19 20@interface NSString : NSObject <NSCopying>21@end22 23@interface NSNumber : NSObject <NSCopying>24+ (NSNumber *)numberWithInt:(int)value;25@end26 27@interface NSArray<T> : NSObject <NSCopying>28+ (instancetype)arrayWithObjects:(const T [])objects count:(NSUInteger)cnt;29@end30 31@interface NSDictionary<K, V> : NSObject <NSCopying>32+ (instancetype)dictionaryWithObjects:(const V [])objects33 forKeys:(const K <NSCopying> [])keys34 count:(NSUInteger)cnt;35@end36 37void testArrayLiteral(void) {38 NSArray<NSString *> *array1 = @[@"hello",39 @1, // expected-warning{{of type 'NSNumber *' is not compatible with array element type 'NSString *'}}40 @"world",41 @[@1, @2]]; // expected-warning{{of type 'NSArray *' is not compatible with array element type 'NSString *'}}42 43 NSArray<NSArray<NSString *> *> *array2 = @[@[@"hello", @"world"],44 @"blah", // expected-warning{{object of type 'NSString *' is not compatible with array element type 'NSArray<NSString *> *'}}45 @[@1]]; // expected-warning{{object of type 'NSNumber *' is not compatible with array element type 'NSString *'}}46}47 48void testDictionaryLiteral(void) {49 NSDictionary<NSString *, NSNumber *> *dict1 = @{50 @"hello" : @17,51 @18 : @18, // expected-warning{{object of type 'NSNumber *' is not compatible with dictionary key type 'NSString *'}}52 @"world" : @"blah" // expected-warning{{object of type 'NSString *' is not compatible with dictionary value type 'NSNumber *'}}53 };54}55 56void testCastingInDictionaryLiteral(NSString *arg) {57 NSDictionary *dict = @{58 (id)arg : @"foo",59 };60}61