annotate clang/test/SemaObjC/objc-container-subscripting.m @ 180:680fa57a2f20

fix compile errors.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 30 May 2020 17:44:06 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 typedef unsigned int size_t;
anatofuz
parents:
diff changeset
4 @protocol P @end
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 @interface NSMutableArray
anatofuz
parents:
diff changeset
7 - (id)objectAtIndexedSubscript:(double)index; // expected-note {{parameter of type 'double' is declared here}}
anatofuz
parents:
diff changeset
8 - (void)setObject:(id *)object atIndexedSubscript:(void *)index; // expected-note {{parameter of type 'void *' is declared here}} \
anatofuz
parents:
diff changeset
9 // expected-note {{parameter of type 'id *' is declared here}}
anatofuz
parents:
diff changeset
10 @end
anatofuz
parents:
diff changeset
11 @interface I @end
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 int main() {
anatofuz
parents:
diff changeset
14 NSMutableArray<P> * array;
anatofuz
parents:
diff changeset
15 id oldObject = array[10]; // expected-error {{method index parameter type 'double' is not integral type}}
anatofuz
parents:
diff changeset
16 array[3] = 0; // expected-error {{method index parameter type 'void *' is not integral type}} \
anatofuz
parents:
diff changeset
17 // expected-error {{cannot assign to this array because assigning method's 2nd parameter of type 'id *' is not an Objective-C pointer type}}
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 I* iarray;
anatofuz
parents:
diff changeset
20 iarray[3] = 0; // expected-error {{expected method to write array element not found on object of type 'I *'}}
anatofuz
parents:
diff changeset
21 I* p = iarray[4]; // expected-error {{expected method to read array element not found on object of type 'I *'}}
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 oldObject = array[10]++; // expected-error {{illegal operation on Objective-C container subscripting}}
anatofuz
parents:
diff changeset
24 oldObject = array[10]--; // expected-error {{illegal operation on Objective-C container subscripting}}
anatofuz
parents:
diff changeset
25 oldObject = --array[10]; // expected-error {{illegal operation on Objective-C container subscripting}}
anatofuz
parents:
diff changeset
26 }
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 @interface NSMutableDictionary
anatofuz
parents:
diff changeset
29 - (id)objectForKeyedSubscript:(id*)key; // expected-note {{parameter of type 'id *' is declared here}}
anatofuz
parents:
diff changeset
30 - (void)setObject:(void*)object forKeyedSubscript:(id*)key; // expected-note {{parameter of type 'void *' is declared here}} \
anatofuz
parents:
diff changeset
31 // expected-note {{parameter of type 'id *' is declared here}}
anatofuz
parents:
diff changeset
32 @end
anatofuz
parents:
diff changeset
33 @class NSString;
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 void testDict() {
anatofuz
parents:
diff changeset
36 NSMutableDictionary *dictionary;
anatofuz
parents:
diff changeset
37 NSString *key;
anatofuz
parents:
diff changeset
38 id newObject, oldObject;
anatofuz
parents:
diff changeset
39 oldObject = dictionary[key]; // expected-error {{method key parameter type 'id *' is not object type}}
anatofuz
parents:
diff changeset
40 dictionary[key] = newObject; // expected-error {{method object parameter type 'void *' is not object type}} \
anatofuz
parents:
diff changeset
41 // expected-error {{method key parameter type 'id *' is not object type}}
anatofuz
parents:
diff changeset
42 }