r248950 - Don't inherit the "unavailable" attribute from an overridden superclass method.

Douglas Gregor via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 30 14:34:33 PDT 2015


Author: dgregor
Date: Wed Sep 30 16:34:33 2015
New Revision: 248950

URL: http://llvm.org/viewvc/llvm-project?rev=248950&view=rev
Log:
Don't inherit the "unavailable" attribute from an overridden superclass method.

Fixes rdar://problem/22922259.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaObjC/attr-availability.m

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=248950&r1=248949&r2=248950&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Sep 30 16:34:33 2015
@@ -2220,12 +2220,10 @@ static bool mergeDeclAttribute(Sema &S,
     // AlignedAttrs are handled separately, because we need to handle all
     // such attributes on a declaration at the same time.
     NewAttr = nullptr;
-  else if (isa<DeprecatedAttr>(Attr)  &&
+  else if ((isa<DeprecatedAttr>(Attr) || isa<UnavailableAttr>(Attr)) &&
            (AMK == Sema::AMK_Override ||
             AMK == Sema::AMK_ProtocolImplementation))
     NewAttr = nullptr;
-  else if (isa<UnavailableAttr>(Attr) && AMK == Sema::AMK_ProtocolImplementation)
-    NewAttr = nullptr;
   else if (Attr->duplicatesAllowed() || !DeclHasAttr(D, Attr))
     NewAttr = cast<InheritableAttr>(Attr->clone(S.Context));
 

Modified: cfe/trunk/test/SemaObjC/attr-availability.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/attr-availability.m?rev=248950&r1=248949&r2=248950&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/attr-availability.m (original)
+++ cfe/trunk/test/SemaObjC/attr-availability.m Wed Sep 30 16:34:33 2015
@@ -278,3 +278,19 @@ __attribute__((objc_root_class))
 -(void)methodB __attribute__((unavailable)) {
 }
 @end
+
+__attribute__((objc_root_class))
+ at interface InheritUnavailableSuper
+-(void)method __attribute__((unavailable)); // expected-note{{'method' has been explicitly marked unavailable here}}
+ at end
+
+ at interface InheritUnavailableSub : InheritUnavailableSuper
+-(void)method;
+ at end
+
+ at implementation InheritUnavailableSub
+-(void)method {
+  InheritUnavailableSuper *obj = self;
+  [obj method]; // expected-error{{'method' is unavailable}}
+}
+ at end




More information about the cfe-commits mailing list