1*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x -fblocks %s 2*67e74705SXin Li 3*67e74705SXin Li// rdar://11231426 4*67e74705SXin Litypedef signed char BOOL; 5*67e74705SXin Li 6*67e74705SXin Livoid y(BOOL (^foo)()); 7*67e74705SXin Li 8*67e74705SXin Livoid x() { 9*67e74705SXin Li y(^{ 10*67e74705SXin Li return __objc_yes; 11*67e74705SXin Li }); 12*67e74705SXin Li} 13*67e74705SXin Li 14*67e74705SXin Li@protocol NSCopying 15*67e74705SXin Li- copy; 16*67e74705SXin Li@end 17*67e74705SXin Li 18*67e74705SXin Li@interface NSObject 19*67e74705SXin Li@end 20*67e74705SXin Li 21*67e74705SXin Li@interface NSNumber : NSObject <NSCopying> 22*67e74705SXin Li-copy; 23*67e74705SXin Li@end 24*67e74705SXin Li 25*67e74705SXin Li@interface NSNumber (NSNumberCreation) 26*67e74705SXin Li+ (NSNumber *)numberWithChar:(char)value; 27*67e74705SXin Li+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value; 28*67e74705SXin Li+ (NSNumber *)numberWithShort:(short)value; 29*67e74705SXin Li+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value; 30*67e74705SXin Li+ (NSNumber *)numberWithInt:(int)value; 31*67e74705SXin Li+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value; 32*67e74705SXin Li+ (NSNumber *)numberWithLong:(long)value; 33*67e74705SXin Li+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value; 34*67e74705SXin Li+ (NSNumber *)numberWithLongLong:(long long)value; 35*67e74705SXin Li+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value; 36*67e74705SXin Li+ (NSNumber *)numberWithFloat:(float)value; 37*67e74705SXin Li+ (NSNumber *)numberWithDouble:(double)value; 38*67e74705SXin Li+ (NSNumber *)numberWithBool:(BOOL)value; 39*67e74705SXin Li@end 40*67e74705SXin Li 41*67e74705SXin Li@interface NSArray : NSObject <NSCopying> 42*67e74705SXin Li-copy; 43*67e74705SXin Li@end 44*67e74705SXin Li 45*67e74705SXin Li@interface NSArray (NSArrayCreation) 46*67e74705SXin Li+ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt; 47*67e74705SXin Li@end 48*67e74705SXin Li 49*67e74705SXin Li@interface NSDictionary 50*67e74705SXin Li+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(unsigned long)cnt; 51*67e74705SXin Li@end 52*67e74705SXin Li 53*67e74705SXin Litemplate<typename T> 54*67e74705SXin Listruct ConvertibleTo { 55*67e74705SXin Li operator T(); 56*67e74705SXin Li}; 57*67e74705SXin Li 58*67e74705SXin Litemplate<typename T> 59*67e74705SXin Listruct ExplicitlyConvertibleTo { 60*67e74705SXin Li explicit operator T(); 61*67e74705SXin Li}; 62*67e74705SXin Li 63*67e74705SXin Litemplate<typename T> 64*67e74705SXin Liclass PrivateConvertibleTo { 65*67e74705SXin Liprivate: 66*67e74705SXin Li operator T(); // expected-note{{declared private here}} 67*67e74705SXin Li}; 68*67e74705SXin Li 69*67e74705SXin Litemplate<typename T> ConvertibleTo<T> makeConvertible(); 70*67e74705SXin Li 71*67e74705SXin Listruct X { 72*67e74705SXin Li ConvertibleTo<id> x; 73*67e74705SXin Li ConvertibleTo<id> get(); 74*67e74705SXin Li}; 75*67e74705SXin Li 76*67e74705SXin Litemplate<typename T> T test_numeric_instantiation() { 77*67e74705SXin Li return @-17.42; 78*67e74705SXin Li} 79*67e74705SXin Li 80*67e74705SXin Litemplate id test_numeric_instantiation(); 81*67e74705SXin Li 82*67e74705SXin Livoid test_convertibility(ConvertibleTo<NSArray*> toArray, 83*67e74705SXin Li ConvertibleTo<id> toId, 84*67e74705SXin Li ConvertibleTo<int (^)(int)> toBlock, 85*67e74705SXin Li ConvertibleTo<int> toInt, 86*67e74705SXin Li ExplicitlyConvertibleTo<NSArray *> toArrayExplicit) { 87*67e74705SXin Li id array = @[ 88*67e74705SXin Li toArray, 89*67e74705SXin Li toId, 90*67e74705SXin Li toBlock, 91*67e74705SXin Li toInt // expected-error{{collection element of type 'ConvertibleTo<int>' is not an Objective-C object}} 92*67e74705SXin Li ]; 93*67e74705SXin Li id array2 = @[ toArrayExplicit ]; // expected-error{{collection element of type 'ExplicitlyConvertibleTo<NSArray *>' is not an Objective-C object}} 94*67e74705SXin Li 95*67e74705SXin Li id array3 = @[ 96*67e74705SXin Li makeConvertible<id>(), 97*67e74705SXin Li makeConvertible<id>, // expected-error{{collection element of type 'ConvertibleTo<id> ()' is not an Objective-C object}} 98*67e74705SXin Li ]; 99*67e74705SXin Li 100*67e74705SXin Li X x; 101*67e74705SXin Li id array4 = @[ x.x ]; 102*67e74705SXin Li id array5 = @[ x.get ]; // expected-error{{reference to non-static member function must be called}} 103*67e74705SXin Li id array6 = @[ PrivateConvertibleTo<NSArray*>() ]; // expected-error{{operator NSArray *' is a private member of 'PrivateConvertibleTo<NSArray *>'}} 104*67e74705SXin Li} 105*67e74705SXin Li 106*67e74705SXin Litemplate<typename T> 107*67e74705SXin Livoid test_array_literals(T t) { 108*67e74705SXin Li id arr = @[ @17, t ]; // expected-error{{collection element of type 'int' is not an Objective-C object}} 109*67e74705SXin Li} 110*67e74705SXin Li 111*67e74705SXin Litemplate void test_array_literals(id); 112*67e74705SXin Litemplate void test_array_literals(NSArray*); 113*67e74705SXin Litemplate void test_array_literals(int); // expected-note{{in instantiation of function template specialization 'test_array_literals<int>' requested here}} 114*67e74705SXin Li 115*67e74705SXin Litemplate<typename T, typename U> 116*67e74705SXin Livoid test_dictionary_literals(T t, U u) { 117*67e74705SXin Li NSObject *object; 118*67e74705SXin Li id dict = @{ 119*67e74705SXin Li @17 : t, // expected-error{{collection element of type 'int' is not an Objective-C object}} 120*67e74705SXin Li u : @42 // expected-error{{collection element of type 'int' is not an Objective-C object}} 121*67e74705SXin Li }; 122*67e74705SXin Li 123*67e74705SXin Li id dict2 = @{ 124*67e74705SXin Li object : @"object" // expected-error{{cannot initialize a parameter of type 'const id<NSCopying>' with an rvalue of type 'NSObject *'}} 125*67e74705SXin Li }; 126*67e74705SXin Li} 127*67e74705SXin Li 128*67e74705SXin Litemplate void test_dictionary_literals(id, NSArray*); 129*67e74705SXin Litemplate void test_dictionary_literals(NSArray*, id); 130*67e74705SXin Litemplate void test_dictionary_literals(int, id); // expected-note{{in instantiation of function template specialization 'test_dictionary_literals<int, id>' requested here}} 131*67e74705SXin Litemplate void test_dictionary_literals(id, int); // expected-note{{in instantiation of function template specialization 'test_dictionary_literals<id, int>' requested here}} 132*67e74705SXin Li 133*67e74705SXin Litemplate<typename ...Args> 134*67e74705SXin Livoid test_bad_variadic_array_literal(Args ...args) { 135*67e74705SXin Li id arr1 = @[ args ]; // expected-error{{initializer contains unexpanded parameter pack 'args'}} 136*67e74705SXin Li} 137*67e74705SXin Li 138*67e74705SXin Litemplate<typename ...Args> 139*67e74705SXin Livoid test_variadic_array_literal(Args ...args) { 140*67e74705SXin Li id arr1 = @[ args... ]; // expected-error{{collection element of type 'int' is not an Objective-C object}} 141*67e74705SXin Li} 142*67e74705SXin Litemplate void test_variadic_array_literal(id); 143*67e74705SXin Litemplate void test_variadic_array_literal(id, NSArray*); 144*67e74705SXin Litemplate void test_variadic_array_literal(id, int, NSArray*); // expected-note{{in instantiation of function template specialization 'test_variadic_array_literal<id, int, NSArray *>' requested here}} 145*67e74705SXin Li 146*67e74705SXin Litemplate<typename ...Args> 147*67e74705SXin Livoid test_bad_variadic_dictionary_literal(Args ...args) { 148*67e74705SXin Li id dict = @{ args : @17 }; // expected-error{{initializer contains unexpanded parameter pack 'args'}} 149*67e74705SXin Li} 150*67e74705SXin Li 151*67e74705SXin Li// Test array literal pack expansions. 152*67e74705SXin Litemplate<typename T, typename U> 153*67e74705SXin Listruct pair { 154*67e74705SXin Li T first; 155*67e74705SXin Li U second; 156*67e74705SXin Li}; 157*67e74705SXin Li 158*67e74705SXin Litemplate<typename T, typename ...Ts, typename ... Us> 159*67e74705SXin Livoid test_variadic_dictionary_expansion(T t, pair<Ts, Us>... key_values) { 160*67e74705SXin Li id dict = @{ 161*67e74705SXin Li t : key_values.second ..., // expected-error{{collection element of type 'int' is not an Objective-C object}} 162*67e74705SXin Li key_values.first : key_values.second ..., // expected-error{{collection element of type 'float' is not an Objective-C object}} 163*67e74705SXin Li key_values.second : t ... 164*67e74705SXin Li }; 165*67e74705SXin Li} 166*67e74705SXin Li 167*67e74705SXin Litemplate void test_variadic_dictionary_expansion(id, 168*67e74705SXin Li pair<NSNumber*, id>, 169*67e74705SXin Li pair<id, ConvertibleTo<id>>); 170*67e74705SXin Litemplate void test_variadic_dictionary_expansion(NSNumber *, // expected-note{{in instantiation of function template specialization}} 171*67e74705SXin Li pair<NSNumber*, int>, 172*67e74705SXin Li pair<id, ConvertibleTo<id>>); 173*67e74705SXin Litemplate void test_variadic_dictionary_expansion(NSNumber *, // expected-note{{in instantiation of function template specialization}} 174*67e74705SXin Li pair<NSNumber*, id>, 175*67e74705SXin Li pair<float, ConvertibleTo<id>>); 176*67e74705SXin Li 177*67e74705SXin Li// Test parsing 178*67e74705SXin Listruct key { 179*67e74705SXin Li static id value; 180*67e74705SXin Li}; 181*67e74705SXin Li 182*67e74705SXin Liid key; 183*67e74705SXin Liid value; 184*67e74705SXin Li 185*67e74705SXin Livoid test_dictionary_colon() { 186*67e74705SXin Li id dict = @{ key : value }; 187*67e74705SXin Li} 188