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