1 // RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin11 -fsyntax-only -std=c++11 -verify %s
5 @interface NSMutableDictionary
6 - (id)objectForKeyedSubscript:(id)key;
7 - (void)setObject:(id)object forKeyedSubscript:(id)key; // expected-note {{passing argument to parameter 'object' here}}
10 template<typename T, typename U, typename O>
11 void test_dictionary_subscripts(T base, U key, O obj) {
12 base[key] = obj; // expected-error {{expected method to write array element not found on object of type 'NSMutableDictionary *'}} \
13 // expected-error {{cannot initialize a parameter of type 'id' with an lvalue of type 'int'}}
14 obj = base[key]; // expected-error {{expected method to read array element not found on object of type 'NSMutableDictionary *'}} \
15 // expected-error {{incompatible pointer to integer conversion assigning to 'int' from 'id'}}
19 template void test_dictionary_subscripts(NSMutableDictionary*, id, NSArray *ns);
21 template void test_dictionary_subscripts(NSMutableDictionary*, NSArray *ns, id);
23 template void test_dictionary_subscripts(NSMutableDictionary*, int, id); // expected-note {{in instantiation of function template specialization 'test_dictionary_subscripts<NSMutableDictionary *, int, id>' requested here}}
25 template void test_dictionary_subscripts(NSMutableDictionary*, id, int); // expected-note {{in instantiation of function template specialization 'test_dictionary_subscripts<NSMutableDictionary *, id, int>' requested here}}
28 @interface NSMutableArray
29 - (id)objectAtIndexedSubscript:(int)index;
30 - (void)setObject:(id)object atIndexedSubscript:(int)index;
33 template<typename T, typename U, typename O>
34 void test_array_subscripts(T base, U index, O obj) {
35 base[index] = obj; // expected-error {{indexing expression is invalid because subscript type 'double' is not an integral or Objective-C pointer type}}
36 obj = base[index]; // expected-error {{indexing expression is invalid because subscript type 'double' is not an integral or Objective-C pointer type}}
39 template void test_array_subscripts(NSMutableArray *, int, id);
40 template void test_array_subscripts(NSMutableArray *, short, id);
43 template void test_array_subscripts(NSMutableArray *, E, id);
45 template void test_array_subscripts(NSMutableArray *, double, id); // expected-note {{in instantiation of function template specialization 'test_array_subscripts<NSMutableArray *, double, id>' requested here}}
48 struct ConvertibleTo {
53 struct ExplicitlyConvertibleTo {
54 explicit operator T();
57 template<typename T> ConvertibleTo<T> makeConvertible();
61 ConvertibleTo<id> get();
64 NSMutableArray *test_array_convertibility(ConvertibleTo<NSMutableArray*> toArray,
65 ConvertibleTo<id> toId,
66 ConvertibleTo<int (^)(int)> toBlock,
67 ConvertibleTo<int> toInt,
68 ExplicitlyConvertibleTo<NSMutableArray *> toArrayExplicit) {
75 toArrayExplicit[2] = toId; // expected-error {{type 'ExplicitlyConvertibleTo<NSMutableArray *>' does not provide a subscript operator}}
81 id test_dict_convertibility(ConvertibleTo<NSMutableDictionary*> toDict,
82 ConvertibleTo<id> toId,
83 ConvertibleTo<int (^)(int)> toBlock,
84 ConvertibleTo<int> toInt,
85 ExplicitlyConvertibleTo<NSMutableDictionary *> toDictExplicit) {
88 NSMutableDictionary *Dict;
92 Dict[toBlock] = toBlock;
94 Dict[toBlock] = Dict[toId] = Dict[toBlock];
96 Id = toDictExplicit[toId] = Id; // expected-error {{no viable overloaded operator[] for type 'ExplicitlyConvertibleTo<NSMutableDictionary *>'}}
102 template<typename ...Args>
103 void test_bad_variadic_array_subscripting(Args ...args) {
105 arr1[3] = args; // expected-error {{expression contains unexpanded parameter pack 'args'}}
108 template<typename ...Args>
109 void test_variadic_array_subscripting(Args ...args) {
110 id arr[] = {args[3]...}; // which means: {a[3], b[3], c[3]};
113 template void test_variadic_array_subscripting(id arg1, NSMutableArray* arg2, id arg3);
117 template<typename Index, typename ...Args>
118 void test_variadic_dictionary_subscripting(Index I, Args ...args) {
119 id arr[] = {args[I]...}; // which means: {a[3], b[3], c[3]};
122 template void test_variadic_dictionary_subscripting(Key *key, id arg1, NSMutableDictionary* arg2, id arg3);
125 id get(NSMutableArray *array) {
126 return array[N]; // array[N] should be a value- and instantiation-dependent ObjCSubscriptRefExpr
130 operator int(); // expected-note {{type conversion function declared here}}
131 operator id(); // expected-note {{type conversion function declared here}}
134 id FUNC(WeirdIndex w) {
135 NSMutableArray *array;
136 return array[w]; // expected-error {{indexing expression is invalid because subscript type 'WeirdIndex' has multiple type conversion functions}}