xref: /aosp_15_r20/external/clang/test/Rewriter/objc-modern-container-subscript.mm (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
2*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
3*67e74705SXin Li// rdar://11203853
4*67e74705SXin Li
5*67e74705SXin Litypedef unsigned long size_t;
6*67e74705SXin Li
7*67e74705SXin Livoid *sel_registerName(const char *);
8*67e74705SXin Li
9*67e74705SXin Li@protocol P @end
10*67e74705SXin Li
11*67e74705SXin Li@interface NSMutableArray
12*67e74705SXin Li#if __has_feature(objc_subscripting)
13*67e74705SXin Li- (id)objectAtIndexedSubscript:(size_t)index;
14*67e74705SXin Li- (void)setObject:(id)object atIndexedSubscript:(size_t)index;
15*67e74705SXin Li#endif
16*67e74705SXin Li@end
17*67e74705SXin Li
18*67e74705SXin Li#if __has_feature(objc_subscripting)
19*67e74705SXin Li@interface XNSMutableArray
20*67e74705SXin Li- (id)objectAtIndexedSubscript:(size_t)index;
21*67e74705SXin Li- (void)setObject:(id)object atIndexedSubscript:(size_t)index;
22*67e74705SXin Li#endif
23*67e74705SXin Li@end
24*67e74705SXin Li
25*67e74705SXin Li@interface NSMutableDictionary
26*67e74705SXin Li- (id)objectForKeyedSubscript:(id)key;
27*67e74705SXin Li- (void)setObject:(id)object forKeyedSubscript:(id)key;
28*67e74705SXin Li@end
29*67e74705SXin Li
30*67e74705SXin Li@class NSString;
31*67e74705SXin Li
32*67e74705SXin Liint main() {
33*67e74705SXin Li  NSMutableArray<P> * array;
34*67e74705SXin Li  id oldObject = array[10];
35*67e74705SXin Li
36*67e74705SXin Li  array[10] = oldObject;
37*67e74705SXin Li
38*67e74705SXin Li  id unknown_array;
39*67e74705SXin Li  oldObject = unknown_array[1];
40*67e74705SXin Li
41*67e74705SXin Li  unknown_array[1] = oldObject;
42*67e74705SXin Li
43*67e74705SXin Li  NSMutableDictionary *dictionary;
44*67e74705SXin Li  NSString *key;
45*67e74705SXin Li  id newObject;
46*67e74705SXin Li  oldObject = dictionary[key];
47*67e74705SXin Li  dictionary[key] = newObject;  // replace oldObject with newObject
48*67e74705SXin Li}
49*67e74705SXin Li
50