blob: 55b6655fa404c8e7142b27ebf380d8a447a1a66d [file] [log] [blame]
John McCalld1e40d52011-10-02 01:16:38 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -fobjc-arc -x objective-c %s.result
2// RUN: arcmt-test --args -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c %s > %t
John McCall8f0e8d22011-06-15 23:25:17 +00003// RUN: diff %t %s.result
Argyrios Kyrtzidisd8b42162012-01-12 02:34:32 +00004// DISABLE: mingw32
John McCall8f0e8d22011-06-15 23:25:17 +00005
6#include "Common.h"
7
John McCall8f0e8d22011-06-15 23:25:17 +00008typedef const struct __CFString * CFStringRef;
9extern const CFStringRef kUTTypePlainText;
10extern const CFStringRef kUTTypeRTF;
11
12typedef const struct __CFAllocator * CFAllocatorRef;
13typedef const struct __CFUUID * CFUUIDRef;
14
15extern const CFAllocatorRef kCFAllocatorDefault;
16
17extern CFStringRef CFUUIDCreateString(CFAllocatorRef alloc, CFUUIDRef uuid);
18
Argyrios Kyrtzidis76a52452012-06-07 00:44:06 +000019struct StrS {
20 CFStringRef sref_member;
21};
22
23@interface NSString : NSObject {
24 CFStringRef sref;
25 struct StrS *strS;
26}
27-(id)string;
28-(id)newString;
29@end
30
John McCall8f0e8d22011-06-15 23:25:17 +000031void f(BOOL b, id p) {
32 NSString *str = (NSString *)kUTTypePlainText;
33 str = b ? kUTTypeRTF : kUTTypePlainText;
34 str = (NSString *)(b ? kUTTypeRTF : kUTTypePlainText);
35 str = (NSString *)p; // no change.
36
John McCall8f0e8d22011-06-15 23:25:17 +000037 CFUUIDRef _uuid;
38 NSString *_uuidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid);
39 _uuidString = [(NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid) autorelease];
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +000040 _uuidString = CFRetain(_uuid);
John McCall8f0e8d22011-06-15 23:25:17 +000041}
Argyrios Kyrtzidis8e2ce7f2011-06-20 23:39:20 +000042
43@implementation NSString (StrExt)
44- (NSString *)stringEscapedAsURI {
45 CFStringRef str = (CFStringRef)self;
46 CFStringRef str2 = self;
47 return self;
48}
49@end
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +000050
Argyrios Kyrtzidis76a52452012-06-07 00:44:06 +000051@implementation NSString
52-(id)string {
53 if (0)
54 return sref;
55 else
56 return strS->sref_member;
57}
58-(id)newString { return 0; }
59@end
60
Argyrios Kyrtzidis4532b552011-09-14 18:17:09 +000061extern void consumeParam(CFStringRef CF_CONSUMED p);
62
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +000063void f2(NSString *s) {
64 CFStringRef ref = [s string];
65 ref = (CFStringRef)[s string];
66 ref = s.string;
67 ref = [NSString new];
68 ref = [s newString];
69 ref = (CFStringRef)[NSString new];
70 ref = [[NSString alloc] init];
71 ref = [[s string] retain];
72 ref = CFRetain((CFStringRef)[s string]);
73 ref = CFRetain([s string]);
74 ref = CFRetain(s);
75 ref = [s retain];
Argyrios Kyrtzidis4532b552011-09-14 18:17:09 +000076
77 consumeParam((CFStringRef)s);
78 consumeParam(s);
Argyrios Kyrtzidis18fd0c62011-07-27 05:28:18 +000079}