[Sema][ObjC] Infer availability of +new from availability of -init.
When defined in NSObject, +new will call -init. If -init has been marked
unavailable, diagnose uses of +new.
rdar://18335828
Differential revision: https://reviews.llvm.org/D51189
llvm-svn: 341874
diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp
index 5f21e3d..1ed7fc7 100644
--- a/clang/lib/AST/DeclObjC.cpp
+++ b/clang/lib/AST/DeclObjC.cpp
@@ -829,6 +829,14 @@
hasAttr<ObjCDesignatedInitializerAttr>();
}
+bool ObjCMethodDecl::definedInNSObject(const ASTContext &Ctx) const {
+ if (const auto *PD = dyn_cast<const ObjCProtocolDecl>(getDeclContext()))
+ return PD->getIdentifier() == Ctx.getNSObjectName();
+ if (const auto *ID = dyn_cast<const ObjCInterfaceDecl>(getDeclContext()))
+ return ID->getIdentifier() == Ctx.getNSObjectName();
+ return false;
+}
+
bool ObjCMethodDecl::isDesignatedInitializerForTheInterface(
const ObjCMethodDecl **InitMethod) const {
if (getMethodFamily() != OMF_init)
diff --git a/clang/lib/AST/NSAPI.cpp b/clang/lib/AST/NSAPI.cpp
index 94ad87b..9d59131 100644
--- a/clang/lib/AST/NSAPI.cpp
+++ b/clang/lib/AST/NSAPI.cpp
@@ -607,3 +607,11 @@
}
return Sel;
}
+
+Selector NSAPI::getOrInitNullarySelector(StringRef Id, Selector &Sel) const {
+ if (Sel.isNull()) {
+ IdentifierInfo *Ident = &Ctx.Idents.get(Id);
+ Sel = Ctx.Selectors.getSelector(0, &Ident);
+ }
+ return Sel;
+}