xref: /aosp_15_r20/external/clang/test/SemaObjC/objcbridgemutable-attribute.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
2*67e74705SXin Li// rdar://15498044
3*67e74705SXin Li
4*67e74705SXin Litypedef struct __attribute__((objc_bridge_mutable(NSMutableDictionary))) __CFDictionary * CFMutableDictionaryRef; // expected-note {{declared here}}
5*67e74705SXin Li
6*67e74705SXin Litypedef struct __attribute__((objc_bridge_mutable(12))) __CFDictionaryB1 * CFMutableDictionaryB1Ref; // expected-error {{parameter of 'objc_bridge_mutable' attribute must be a single name of an Objective-C class}}
7*67e74705SXin Li
8*67e74705SXin Litypedef struct __attribute__((objc_bridge_mutable(P))) __CFDictionaryB2 * CFMutableDictionaryB2Ref; // expected-note {{declared here}}
9*67e74705SXin Li
10*67e74705SXin Litypedef struct __attribute__((objc_bridge_mutable(NSMutableDictionary, Unknown))) __CFDictionaryB3 * CFMutableDictionaryB3Ref;  // expected-error {{use of undeclared identifier 'Unknown'}}
11*67e74705SXin Li
12*67e74705SXin Litypedef struct __attribute__((objc_bridge_mutable)) __CFDictionaryB4 * CFMutableDictionaryB4Ref;  // expected-error {{'objc_bridge_mutable' attribute takes one argument}}
13*67e74705SXin Li
14*67e74705SXin Li@interface NSDictionary
15*67e74705SXin Li@end
16*67e74705SXin Li
17*67e74705SXin Li@interface NSMutableDictionary : NSDictionary
18*67e74705SXin Li@end
19*67e74705SXin Li
20*67e74705SXin Li@protocol P @end
21*67e74705SXin Li
22*67e74705SXin Livoid Test(NSMutableDictionary *md, NSDictionary *nd, CFMutableDictionaryRef mcf, CFMutableDictionaryB2Ref bmcf) {
23*67e74705SXin Li
24*67e74705SXin Li  (void) (CFMutableDictionaryRef)md;
25*67e74705SXin Li  (void) (CFMutableDictionaryRef)nd; // expected-warning {{'NSDictionary' cannot bridge to 'CFMutableDictionaryRef' (aka 'struct __CFDictionary *')}}
26*67e74705SXin Li  (void) (NSDictionary *)mcf; // ok, bridgt_type NSMutableDictionary can be type-cast to its super class.
27*67e74705SXin Li  NSDictionary *nsdobj = (NSMutableDictionary*)0;
28*67e74705SXin Li  (void) (NSMutableDictionary *)mcf; // ok;
29*67e74705SXin Li  (void) (NSMutableDictionary *)bmcf; // expected-error {{CF object of type 'CFMutableDictionaryB2Ref' (aka 'struct __CFDictionaryB2 *') is bridged to 'P', which is not an Objective-C class}}
30*67e74705SXin Li
31*67e74705SXin Li}
32*67e74705SXin Li
33