Define weak and __weak to mean ARC-style weak references, even in MRC.
Previously, __weak was silently accepted and ignored in MRC mode.
That makes this a potentially source-breaking change that we have to
roll out cautiously. Accordingly, for the time being, actual support
for __weak references in MRC is experimental, and the compiler will
reject attempts to actually form such references. The intent is to
eventually enable the feature by default in all non-GC modes.
(It is, of course, incompatible with ObjC GC's interpretation of
__weak.)
If you like, you can enable this feature with
-Xclang -fobjc-weak
but like any -Xclang option, this option may be removed at any point,
e.g. if/when it is eventually enabled by default.
This patch also enables the use of the ARC __unsafe_unretained qualifier
in MRC. Unlike __weak, this is being enabled immediately. Since
variables are essentially __unsafe_unretained by default in MRC,
the only practical uses are (1) communication and (2) changing the
default behavior of by-value block capture.
As an implementation matter, this means that the ObjC ownership
qualifiers may appear in any ObjC language mode, and so this patch
removes a number of checks for getLangOpts().ObjCAutoRefCount
that were guarding the processing of these qualifiers. I don't
expect this to be a significant drain on performance; it may even
be faster to just check for these qualifiers directly on a type
(since it's probably in a register anyway) than to do N dependent
loads to grab the LangOptions.
rdar://9674298
llvm-svn: 251041
2015-10-23 02:38:17 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fobjc-weak -verify -Weverything -Wno-objc-weak-compat %s
|
|
|
|
// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fobjc-weak -fsyntax-only -verify -Weverything -Wno-objc-weak-compat %s
|
2012-08-22 05:45:58 +08:00
|
|
|
// rdar://12103400
|
|
|
|
|
|
|
|
@class NSString;
|
|
|
|
|
|
|
|
@interface MyClass
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) NSString* addingMemoryModel;
|
|
|
|
|
2013-12-14 02:19:59 +08:00
|
|
|
@property (nonatomic, copy, readonly) NSString* matchingMemoryModel;
|
2012-08-22 05:45:58 +08:00
|
|
|
|
2013-12-14 02:19:59 +08:00
|
|
|
@property (nonatomic, retain, readonly) NSString* addingNoNewMemoryModel;
|
2012-08-22 05:45:58 +08:00
|
|
|
|
|
|
|
@property (readonly) NSString* none;
|
|
|
|
@property (readonly) NSString* none1;
|
|
|
|
|
2013-12-14 02:19:59 +08:00
|
|
|
@property (assign, readonly) NSString* changeMemoryModel; // expected-note {{property declared here}}
|
2012-08-22 05:45:58 +08:00
|
|
|
|
|
|
|
@property (readonly) __weak id weak_prop;
|
|
|
|
@property (readonly) __weak id weak_prop1;
|
|
|
|
|
2013-12-14 02:19:59 +08:00
|
|
|
@property (assign, readonly) NSString* assignProperty;
|
2012-08-22 05:45:58 +08:00
|
|
|
|
|
|
|
@property (readonly) NSString* readonlyProp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface MyClass ()
|
|
|
|
{
|
|
|
|
NSString* _name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@property (nonatomic, copy) NSString* addingMemoryModel;
|
|
|
|
@property (nonatomic, copy) NSString* matchingMemoryModel;
|
2012-09-18 07:57:35 +08:00
|
|
|
@property () NSString* addingNoNewMemoryModel;
|
|
|
|
@property () NSString* none;
|
2012-09-18 04:57:19 +08:00
|
|
|
@property (readwrite, retain) NSString* none1;
|
2012-08-22 05:45:58 +08:00
|
|
|
|
|
|
|
@property (retain) NSString* changeMemoryModel; // expected-warning {{property attribute in class extension does not match the primary class}}
|
2012-09-18 07:57:35 +08:00
|
|
|
@property () __weak id weak_prop;
|
|
|
|
@property (readwrite) __weak id weak_prop1;
|
2012-08-22 05:45:58 +08:00
|
|
|
|
2012-09-18 04:57:19 +08:00
|
|
|
@property (assign, readwrite) NSString* assignProperty;
|
2012-08-22 05:45:58 +08:00
|
|
|
@property (assign) NSString* readonlyProp;
|
|
|
|
@end
|
|
|
|
|
2012-09-18 04:57:19 +08:00
|
|
|
// rdar://12214070
|
|
|
|
@interface radar12214070
|
|
|
|
@property (nonatomic, atomic, readonly) float propertyName; // expected-error {{property attributes 'atomic' and 'nonatomic' are mutually exclusive}}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface radar12214070 ()
|
|
|
|
@property (atomic, nonatomic, readonly, readwrite) float propertyName; // expected-error {{property attributes 'readonly' and 'readwrite' are mutually exclusive}} \
|
|
|
|
// expected-error {{property attributes 'atomic' and 'nonatomic' are mutually exclusive}}
|
|
|
|
@end
|
|
|
|
|