]> granicus.if.org Git - clang/commitdiff
Don't inherit the "unavailable" attribute from an overridden superclass method.
authorDouglas Gregor <dgregor@apple.com>
Wed, 30 Sep 2015 21:34:33 +0000 (21:34 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 30 Sep 2015 21:34:33 +0000 (21:34 +0000)
Fixes rdar://problem/22922259.

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

lib/Sema/SemaDecl.cpp
test/SemaObjC/attr-availability.m

index a359ef49311564481bf0cfe47f50dbab5e57b5fa..467b36dfeec0d132d3239b6ab21cef14beda0242 100644 (file)
@@ -2220,12 +2220,10 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
     // 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));
 
index 8323139e59021cf5834fd3bad06d702a9252cd0e..dad2d5b7e794d6866881fc7de77568ecc5336d22 100644 (file)
@@ -278,3 +278,19 @@ __attribute__((objc_root_class))
 -(void)methodB __attribute__((unavailable)) {
 }
 @end
+
+__attribute__((objc_root_class))
+@interface InheritUnavailableSuper
+-(void)method __attribute__((unavailable)); // expected-note{{'method' has been explicitly marked unavailable here}}
+@end
+
+@interface InheritUnavailableSub : InheritUnavailableSuper
+-(void)method;
+@end
+
+@implementation InheritUnavailableSub
+-(void)method {
+  InheritUnavailableSuper *obj = self;
+  [obj method]; // expected-error{{'method' is unavailable}}
+}
+@end