comparison clang/test/SemaObjC/illegal-nonarc-bridged-cast.m @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children c4bab56944e8
comparison
equal deleted inserted replaced
147:c2174574ed3a 150:1d019706d866
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fblocks -Wcast-qual -verify %s
2 // rdar://10597832
3
4 typedef const void *CFTypeRef;
5 typedef const struct __CFString *CFStringRef;
6 @class NSString;
7
8 @interface NSString
9 @end
10
11 CFTypeRef CFCreateSomething();
12 CFStringRef CFCreateString();
13 CFTypeRef CFGetSomething();
14 CFStringRef CFGetString();
15
16 id CreateSomething();
17 NSString *CreateNSString();
18
19 void from_cf() {
20 id obj1 = (__bridge_transfer id)CFCreateSomething(); // expected-warning {{'__bridge_transfer' casts have no effect when not using ARC}}
21 id obj2 = (__bridge_transfer NSString*)CFCreateString(); // expected-warning {{'__bridge_transfer' casts have no effect when not using ARC}}
22 (__bridge int*)CFCreateSomething(); // expected-warning {{expression result unused}} expected-warning {{cast from 'const void *' to 'int *' drops const qualifier}}
23 id obj3 = (__bridge id)CFGetSomething();
24 id obj4 = (__bridge NSString*)CFGetString();
25 }
26
27 void to_cf(id obj) {
28 CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); // expected-warning {{'__bridge_retained' casts have no effect when not using ARC}}
29 CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString(); // expected-warning {{'__bridge_retained' casts have no effect when not using ARC}}
30 CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething();
31 CFStringRef cf4 = (__bridge CFStringRef)CreateNSString();
32 }
33
34 void fixits() {
35 id obj1 = (id)CFCreateSomething();
36 CFTypeRef cf1 = (CFTypeRef)CreateSomething();
37 }
38
39 #pragma clang diagnostic ignored "-Warc-bridge-casts-disallowed-in-nonarc"
40
41 void to_cf_ignored(id obj) {
42 CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); // no-warning
43 CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); // no-warning
44 }
45
46 // Check that clang doesn't warn about dropping const from Objective-C object
47 // types.
48 void test_wcast_qual() {
49 CFStringRef c;
50 NSString *n0 = (NSString *)c;
51 NSString **n1 = (NSString **)&c;
52 const NSString *n2;
53 const NSString **n3;
54 void *p0 = (void *)n2;
55 void **p1 = (void **)n3;
56 }