]> granicus.if.org Git - clang/commitdiff
[ObjC] Check written attributes only when synthesizing ambiguous property
authorAlex Lorenz <arphaman@gmail.com>
Tue, 22 Aug 2017 10:38:07 +0000 (10:38 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Tue, 22 Aug 2017 10:38:07 +0000 (10:38 +0000)
This commit fixes a bug introduced in r307903. The attribute ambiguity checker
that was introduced in r307903 checked all property attributes, which caused
errors for source-compatible properties, like:

@property (nonatomic, readonly) NSObject *prop;
@property (nonatomic, readwrite) NSObject *prop;

because the readwrite property would get implicit 'strong' attribute. The
ambiguity checker should be concerned about explicitly specified attributes
only.

rdar://33748089

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311443 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaObjCProperty.cpp
test/SemaObjC/arc-property-decl-attrs.m

index d0b59eb7895141ad2983b55f2551c238d139ce54..18f509caaa0c0f8df3c0e593831834ae800a5eca 100644 (file)
@@ -872,7 +872,7 @@ SelectPropertyForSynthesisFromProtocols(Sema &S, SourceLocation AtLoc,
   }
 
   QualType RHSType = S.Context.getCanonicalType(Property->getType());
-  unsigned OriginalAttributes = Property->getPropertyAttributes();
+  unsigned OriginalAttributes = Property->getPropertyAttributesAsWritten();
   enum MismatchKind {
     IncompatibleType = 0,
     HasNoExpectedAttribute,
@@ -890,7 +890,7 @@ SelectPropertyForSynthesisFromProtocols(Sema &S, SourceLocation AtLoc,
   SmallVector<MismatchingProperty, 4> Mismatches;
   for (ObjCPropertyDecl *Prop : Properties) {
     // Verify the property attributes.
-    unsigned Attr = Prop->getPropertyAttributes();
+    unsigned Attr = Prop->getPropertyAttributesAsWritten();
     if (Attr != OriginalAttributes) {
       auto Diag = [&](bool OriginalHasAttribute, StringRef AttributeName) {
         MismatchKind Kind = OriginalHasAttribute ? HasNoExpectedAttribute
index ee48d310edc0a27f0578706a8ce95017702fc60b..7393f58199f9a85658dc490dd150d1349e6af590 100644 (file)
@@ -225,3 +225,30 @@ __attribute__((objc_root_class))
 @implementation TypeVsSetter
 @synthesize prop; // expected-note {{property synthesized here}}
 @end
+
+@protocol AutoStrongProp
+
+@property (nonatomic, readonly) NSObject *prop;
+
+@end
+
+@protocol AutoStrongProp_Internal <AutoStrongProp>
+
+// This property gets the 'strong' attribute automatically.
+@property (nonatomic, readwrite) NSObject *prop;
+
+@end
+
+@interface SynthesizeWithImplicitStrongNoError : NSObject <AutoStrongProp>
+@end
+
+@interface SynthesizeWithImplicitStrongNoError () <AutoStrongProp_Internal>
+
+@end
+
+@implementation SynthesizeWithImplicitStrongNoError
+
+// no error, 'strong' is implicit in the 'readwrite' property.
+@synthesize prop = _prop;
+
+@end