From: Douglas Gregor Date: Wed, 30 Sep 2015 21:34:33 +0000 (+0000) Subject: Don't inherit the "unavailable" attribute from an overridden superclass method. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4090e3ae47340ad66021227119da3e9a1e7fa345;p=clang Don't inherit the "unavailable" attribute from an overridden superclass method. Fixes rdar://problem/22922259. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248950 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index a359ef4931..467b36dfee 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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(Attr) && + else if ((isa(Attr) || isa(Attr)) && (AMK == Sema::AMK_Override || AMK == Sema::AMK_ProtocolImplementation)) NewAttr = nullptr; - else if (isa(Attr) && AMK == Sema::AMK_ProtocolImplementation) - NewAttr = nullptr; else if (Attr->duplicatesAllowed() || !DeclHasAttr(D, Attr)) NewAttr = cast(Attr->clone(S.Context)); diff --git a/test/SemaObjC/attr-availability.m b/test/SemaObjC/attr-availability.m index 8323139e59..dad2d5b7e7 100644 --- a/test/SemaObjC/attr-availability.m +++ b/test/SemaObjC/attr-availability.m @@ -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