diff options
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 23 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 20 |
2 files changed, 36 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 73fd057a2a5..287632382dd 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -6484,3 +6484,26 @@ void Sema::EmitAvailabilityWarning(AvailabilityDiagnostic AD, DoEmitAvailabilityWarning(*this, AD, Ctx, D, Message, Loc, UnknownObjCClass, ObjCProperty, ObjCPropertyAccess); } + +VersionTuple Sema::getVersionForDecl(const Decl *D) const { + assert(D && "Expected a declaration here!"); + + VersionTuple DeclVersion; + if (const auto *AA = getAttrForPlatform(getASTContext(), D)) + DeclVersion = AA->getIntroduced(); + + const ObjCInterfaceDecl *Interface = nullptr; + + if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) + Interface = MD->getClassInterface(); + else if (const auto *ID = dyn_cast<ObjCImplementationDecl>(D)) + Interface = ID->getClassInterface(); + + if (Interface) { + if (const auto *AA = getAttrForPlatform(getASTContext(), Interface)) + if (AA->getIntroduced() > DeclVersion) + DeclVersion = AA->getIntroduced(); + } + + return DeclVersion; +} diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 19a3d035d37..6539790224d 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -107,9 +107,14 @@ static AvailabilityResult DiagnoseAvailabilityOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, bool ObjCPropertyAccess) { - // See if this declaration is unavailable or deprecated. + VersionTuple ContextVersion; + if (const DeclContext *DC = S.getCurObjCLexicalContext()) + ContextVersion = S.getVersionForDecl(cast<Decl>(DC)); + + // See if this declaration is unavailable, deprecated, or partial in the + // current context. std::string Message; - AvailabilityResult Result = D->getAvailability(&Message); + AvailabilityResult Result = D->getAvailability(&Message, ContextVersion); // For typedefs, if the typedef declaration appears available look // to the underlying type to see if it is more restrictive. @@ -117,7 +122,7 @@ DiagnoseAvailabilityOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc, if (Result == AR_Available) { if (const TagType *TT = TD->getUnderlyingType()->getAs<TagType>()) { D = TT->getDecl(); - Result = D->getAvailability(&Message); + Result = D->getAvailability(&Message, ContextVersion); continue; } } @@ -128,7 +133,7 @@ DiagnoseAvailabilityOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc, if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(D)) { if (IDecl->getDefinition()) { D = IDecl->getDefinition(); - Result = D->getAvailability(&Message); + Result = D->getAvailability(&Message, ContextVersion); } } @@ -136,7 +141,7 @@ DiagnoseAvailabilityOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc, if (Result == AR_Available) { const DeclContext *DC = ECD->getDeclContext(); if (const EnumDecl *TheEnumDecl = dyn_cast<EnumDecl>(DC)) - Result = TheEnumDecl->getAvailability(&Message); + Result = TheEnumDecl->getAvailability(&Message, ContextVersion); } const ObjCPropertyDecl *ObjCPDecl = nullptr; @@ -144,7 +149,8 @@ DiagnoseAvailabilityOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc, Result == AR_NotYetIntroduced) { if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) { if (const ObjCPropertyDecl *PD = MD->findPropertyDecl()) { - AvailabilityResult PDeclResult = PD->getAvailability(nullptr); + AvailabilityResult PDeclResult = + PD->getAvailability(nullptr, ContextVersion); if (PDeclResult == Result) ObjCPDecl = PD; } @@ -198,7 +204,7 @@ DiagnoseAvailabilityOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc, break; } - return Result; + return Result; } /// \brief Emit a note explaining that this function is deleted. |

