1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 typedef unsigned int size_t;
6 @interface NSMutableArray
7 - (id)objectAtIndexedSubscript:(size_t)index;
8 - (void)setObject:(id)object atIndexedSubscript:(size_t)index;
11 @interface NSMutableDictionary
12 - (id)objectForKeyedSubscript:(id)key;
13 - (void)setObject:(id)object forKeyedSubscript:(size_t)key;
17 NSMutableArray *array;
19 array[f] = array; // expected-error {{indexing expression is invalid because subscript type 'float' is not an integral or Objective-C pointer type}}
20 return array[3.14]; // expected-error {{indexing expression is invalid because subscript type 'double' is not an integral or Objective-C pointer type}}
23 void test_unused(void) {
24 NSMutableArray *array;
25 array[10]; // expected-warning {{container access result unused - container access should not be used for side effects}}
27 NSMutableDictionary *dict;
28 dict[array]; // expected-warning {{container access result unused - container access should not be used for side effects}}
31 void testQualifiedId(id<P> qualifiedId) {
32 id object = qualifiedId[10]; // expected-error {{expected method to read array element not found on object of type 'id<P>'}}
33 qualifiedId[10] = qualifiedId; // expected-error {{expected method to write array element not found on object of type 'id<P>'}}
36 void testUnqualifiedId(id unqualId) {
37 id object = unqualId[10];
38 unqualId[10] = object;
41 @protocol Subscriptable
42 - (id)objectAtIndexedSubscript:(size_t)index;
43 - (void)setObject:(id)object atIndexedSubscript:(size_t)index;
46 void testValidQualifiedId(id<Subscriptable> qualifiedId) {
47 id object = qualifiedId[10];
48 qualifiedId[10] = object;