xref: /aosp_15_r20/external/clang/test/SemaObjC/arc-dict-bridged-cast.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify %s
2*67e74705SXin Li// RUN: not %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
3*67e74705SXin Li// rdar://11913153
4*67e74705SXin Li
5*67e74705SXin Litypedef const struct __CFString * CFStringRef;
6*67e74705SXin Litypedef struct __CFString * CFMutableStringRef;
7*67e74705SXin Litypedef signed long CFIndex;
8*67e74705SXin Litypedef const struct __CFAllocator * CFAllocatorRef;
9*67e74705SXin Li
10*67e74705SXin Liextern const CFStringRef kCFBundleNameKey;
11*67e74705SXin Li
12*67e74705SXin Li@protocol NSCopying @end
13*67e74705SXin Li
14*67e74705SXin Li@interface NSDictionary
15*67e74705SXin Li- (id)objectForKeyedSubscript:(id<NSCopying>)key;
16*67e74705SXin Li@end
17*67e74705SXin Li
18*67e74705SXin Li#pragma clang arc_cf_code_audited begin
19*67e74705SXin Liextern
20*67e74705SXin LiCFMutableStringRef CFStringCreateMutable(CFAllocatorRef alloc, CFIndex maxLength);
21*67e74705SXin Li#pragma clang arc_cf_code_audited end
22*67e74705SXin Li
23*67e74705SXin Litypedef const void * CFTypeRef;
24*67e74705SXin Li
25*67e74705SXin Liid CFBridgingRelease(CFTypeRef __attribute__((cf_consumed)) X);
26*67e74705SXin Li
27*67e74705SXin Li@interface NSMutableString @end
28*67e74705SXin Li
29*67e74705SXin LiNSMutableString *test() {
30*67e74705SXin Li  NSDictionary *infoDictionary;
31*67e74705SXin Li  infoDictionary[kCFBundleNameKey] = 0; // expected-error {{indexing expression is invalid because subscript type 'CFStringRef' (aka 'const struct __CFString *') is not an integral or Objective-C pointer type}}
32*67e74705SXin Li  return infoDictionary[CFStringCreateMutable(((void*)0), 100)]; // expected-error {{indexing expression is invalid because subscript type 'CFMutableStringRef' (aka 'struct __CFString *') is not an integral or Objective-C pointer type}} \
33*67e74705SXin Li                                       // expected-error {{implicit conversion of C pointer type 'CFMutableStringRef' (aka 'struct __CFString *') to Objective-C pointer type '__strong id<NSCopying>' requires a bridged cast}} \
34*67e74705SXin Li                                        // expected-note {{use CFBridgingRelease call to transfer ownership of a +1 'CFMutableStringRef' (aka 'struct __CFString *') into ARC}}
35*67e74705SXin Li
36*67e74705SXin Li}
37*67e74705SXin Li
38*67e74705SXin Li// CHECK: fix-it:"{{.*}}":{32:25-32:25}:"CFBridgingRelease("
39*67e74705SXin Li// CHECK: fix-it:"{{.*}}":{32:63-32:63}:")"
40