blob: 7913661787e509c12efb1ecd62280e415df57f6a [file] [log] [blame]
John McCall9b0a7ce2011-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 McCalld70fb982011-06-15 23:25:17 +00003// RUN: diff %t %s.result
4
5#include "Common.h"
6
John McCalld70fb982011-06-15 23:25:17 +00007typedef const struct __CFString * CFStringRef;
8extern const CFStringRef kUTTypePlainText;
9extern const CFStringRef kUTTypeRTF;
Ben Langmuir443aa4b2015-02-25 20:09:06 +000010extern CFStringRef kNonConst;
John McCalld70fb982011-06-15 23:25:17 +000011
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 Kyrtzidisb03cc792012-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 McCalld70fb982011-06-15 23:25:17 +000031void f(BOOL b, id p) {
Ben Langmuir443aa4b2015-02-25 20:09:06 +000032 NSString *str = (NSString *)kUTTypePlainText; // no change
33 str = b ? kUTTypeRTF : kUTTypePlainText; // no change
34 str = (NSString *)(b ? kUTTypeRTF : kUTTypePlainText); // no change
John McCalld70fb982011-06-15 23:25:17 +000035 str = (NSString *)p; // no change.
36
Ben Langmuir443aa4b2015-02-25 20:09:06 +000037 str = (NSString *)kNonConst;
38 str = b ? kUTTypeRTF : kNonConst;
39 str = (NSString *)(b ? kUTTypeRTF : kNonConst);
40
John McCalld70fb982011-06-15 23:25:17 +000041 CFUUIDRef _uuid;
42 NSString *_uuidString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid);
43 _uuidString = [(NSString *)CFUUIDCreateString(kCFAllocatorDefault, _uuid) autorelease];
Argyrios Kyrtzidis93907472011-07-27 05:28:18 +000044 _uuidString = CFRetain(_uuid);
John McCalld70fb982011-06-15 23:25:17 +000045}
Argyrios Kyrtzidis0a9d6522011-06-20 23:39:20 +000046
47@implementation NSString (StrExt)
48- (NSString *)stringEscapedAsURI {
49 CFStringRef str = (CFStringRef)self;
50 CFStringRef str2 = self;
51 return self;
52}
53@end
Argyrios Kyrtzidis93907472011-07-27 05:28:18 +000054
Argyrios Kyrtzidisb03cc792012-06-07 00:44:06 +000055@implementation NSString
56-(id)string {
57 if (0)
58 return sref;
59 else
60 return strS->sref_member;
61}
62-(id)newString { return 0; }
63@end
64
Argyrios Kyrtzidis41899f32011-09-14 18:17:09 +000065extern void consumeParam(CFStringRef CF_CONSUMED p);
66
Argyrios Kyrtzidis93907472011-07-27 05:28:18 +000067void f2(NSString *s) {
68 CFStringRef ref = [s string];
69 ref = (CFStringRef)[s string];
70 ref = s.string;
71 ref = [NSString new];
72 ref = [s newString];
73 ref = (CFStringRef)[NSString new];
74 ref = [[NSString alloc] init];
75 ref = [[s string] retain];
76 ref = CFRetain((CFStringRef)[s string]);
77 ref = CFRetain([s string]);
78 ref = CFRetain(s);
79 ref = [s retain];
Argyrios Kyrtzidis41899f32011-09-14 18:17:09 +000080
81 consumeParam((CFStringRef)s);
82 consumeParam(s);
Argyrios Kyrtzidis93907472011-07-27 05:28:18 +000083}