1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x -fblocks %s
3 typedef signed char BOOL;
20 @interface NSNumber : NSObject <NSCopying>
24 @interface NSNumber (NSNumberCreation)
25 + (NSNumber *)numberWithChar:(char)value;
26 + (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
27 + (NSNumber *)numberWithShort:(short)value;
28 + (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
29 + (NSNumber *)numberWithInt:(int)value;
30 + (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
31 + (NSNumber *)numberWithLong:(long)value;
32 + (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
33 + (NSNumber *)numberWithLongLong:(long long)value;
34 + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
35 + (NSNumber *)numberWithFloat:(float)value;
36 + (NSNumber *)numberWithDouble:(double)value;
37 + (NSNumber *)numberWithBool:(BOOL)value;
40 @interface NSArray : NSObject <NSCopying>
44 @interface NSArray (NSArrayCreation)
45 + (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
48 @interface NSDictionary
49 + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id<NSCopying> [])keys count:(unsigned long)cnt;
56 struct ConvertibleTo {
61 struct ExplicitlyConvertibleTo {
62 explicit operator T();
66 class PrivateConvertibleTo {
68 operator T(); // expected-note{{declared private here}}
71 template<typename T> ConvertibleTo<T> makeConvertible();
75 ConvertibleTo<id> get();
78 template<typename T> T test_numeric_instantiation() {
82 template id test_numeric_instantiation();
84 void test_convertibility(ConvertibleTo<NSArray*> toArray,
85 ConvertibleTo<id> toId,
86 ConvertibleTo<int (^)(int)> toBlock,
87 ConvertibleTo<int> toInt,
88 ExplicitlyConvertibleTo<NSArray *> toArrayExplicit) {
93 toInt // expected-error{{collection element of type 'ConvertibleTo<int>' is not an Objective-C object}}
95 id array2 = @[ toArrayExplicit ]; // expected-error{{collection element of type 'ExplicitlyConvertibleTo<NSArray *>' is not an Objective-C object}}
98 makeConvertible<id>(),
99 makeConvertible<id>, // expected-error{{collection element of type 'ConvertibleTo<id> ()' is not an Objective-C object}}
103 id array4 = @[ x.x ];
104 id array5 = @[ x.get ]; // expected-error{{reference to non-static member function must be called}}
105 id array6 = @[ PrivateConvertibleTo<NSArray*>() ]; // expected-error{{operator NSArray *' is a private member of 'PrivateConvertibleTo<NSArray *>'}}
109 void test_array_literals(T t) {
110 id arr = @[ @17, t ]; // expected-error{{collection element of type 'int' is not an Objective-C object}}
113 template void test_array_literals(id);
114 template void test_array_literals(NSArray*);
115 template void test_array_literals(int); // expected-note{{in instantiation of function template specialization 'test_array_literals<int>' requested here}}
117 template<typename T, typename U>
118 void test_dictionary_literals(T t, U u) {
121 @17 : t, // expected-error{{collection element of type 'int' is not an Objective-C object}}
122 u : @42 // expected-error{{collection element of type 'int' is not an Objective-C object}}
126 object : @"object" // expected-error{{cannot initialize a parameter of type 'const id<NSCopying>' with an rvalue of type 'NSObject *'}}
130 template void test_dictionary_literals(id, NSArray*);
131 template void test_dictionary_literals(NSArray*, id);
132 template void test_dictionary_literals(int, id); // expected-note{{in instantiation of function template specialization 'test_dictionary_literals<int, id>' requested here}}
133 template void test_dictionary_literals(id, int); // expected-note{{in instantiation of function template specialization 'test_dictionary_literals<id, int>' requested here}}
135 template<typename ...Args>
136 void test_bad_variadic_array_literal(Args ...args) {
137 id arr1 = @[ args ]; // expected-error{{initializer contains unexpanded parameter pack 'args'}}
140 template<typename ...Args>
141 void test_variadic_array_literal(Args ...args) {
142 id arr1 = @[ args... ]; // expected-error{{collection element of type 'int' is not an Objective-C object}}
144 template void test_variadic_array_literal(id);
145 template void test_variadic_array_literal(id, NSArray*);
146 template 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}}
148 template<typename ...Args>
149 void test_bad_variadic_dictionary_literal(Args ...args) {
150 id dict = @{ args : @17 }; // expected-error{{initializer contains unexpanded parameter pack 'args'}}
153 // Test array literal pack expansions.
154 template<typename T, typename U>
160 template<typename T, typename ...Ts, typename ... Us>
161 void test_variadic_dictionary_expansion(T t, pair<Ts, Us>... key_values) {
163 t : key_values.second ..., // expected-error{{collection element of type 'int' is not an Objective-C object}}
164 key_values.first : key_values.second ..., // expected-error{{collection element of type 'float' is not an Objective-C object}}
165 key_values.second : t ...
169 template void test_variadic_dictionary_expansion(id,
171 pair<id, ConvertibleTo<id>>);
172 template void test_variadic_dictionary_expansion(NSNumber *, // expected-note{{in instantiation of function template specialization}}
173 pair<NSNumber*, int>,
174 pair<id, ConvertibleTo<id>>);
175 template void test_variadic_dictionary_expansion(NSNumber *, // expected-note{{in instantiation of function template specialization}}
177 pair<float, ConvertibleTo<id>>);
187 void test_dictionary_colon() {
188 id dict = @{ key : value };
191 void testConstExpr() {
192 constexpr NSString *t0 = @"abc";
193 constexpr NSString *t1 = @("abc");