aboutsummaryrefslogtreecommitdiff
path: root/test/ARCMT/nonobjc-to-objc-cast-2.m
diff options
context:
space:
mode:
Diffstat (limited to 'test/ARCMT/nonobjc-to-objc-cast-2.m')
-rw-r--r--test/ARCMT/nonobjc-to-objc-cast-2.m25
1 files changed, 21 insertions, 4 deletions
diff --git a/test/ARCMT/nonobjc-to-objc-cast-2.m b/test/ARCMT/nonobjc-to-objc-cast-2.m
index 46ef02400e8c..5dba61f023fd 100644
--- a/test/ARCMT/nonobjc-to-objc-cast-2.m
+++ b/test/ARCMT/nonobjc-to-objc-cast-2.m
@@ -1,9 +1,13 @@
-// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi %s
+// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 %s
-typedef int BOOL;
-typedef const struct __CFString * CFStringRef;
+#include "Common.h"
+
+@interface NSString : NSObject
+-(id)string;
+-(id)newString;
+@end
-@class NSString;
+typedef const struct __CFString * CFStringRef;
void f(BOOL b) {
CFStringRef cfstr;
@@ -12,3 +16,16 @@ void f(BOOL b) {
// expected-note{{use __bridge_transfer to transfer ownership of a +1 'CFStringRef' (aka 'const struct __CFString *') into ARC}}
void *vp = str; // expected-error {{disallowed}}
}
+
+void f2(NSString *s) {
+ CFStringRef ref;
+ ref = [(CFStringRef)[s string] retain]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast}} \
+ // expected-error {{ bad receiver type 'CFStringRef' (aka 'const struct __CFString *')}} \
+ // expected-note{{use __bridge to convert directly (no change in ownership)}} \
+ // expected-note{{use __bridge_retained to make an ARC object available as a +1 'CFStringRef' (aka 'const struct __CFString *')}}
+}
+
+CFStringRef f3() {
+ return (CFStringRef)[[[NSString alloc] init] autorelease]; // expected-error {{it is not safe to cast to 'CFStringRef' the result of 'autorelease' message; a __bridge cast may result in a pointer to a destroyed object and a __bridge_retained may leak the object}} \
+ // expected-note {{remove the cast and change return type of function to 'NSString *' to have the object automatically autoreleased}}
+}