summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclObjC.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-03-02 19:05:07 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-03-02 19:05:07 +0000
commit33afd771b46c29c420cbf8e926330850db36b43a (patch)
tree689db19dfd0bd960ff8801a151c9d63e712ca8eb /clang/lib/Sema/SemaDeclObjC.cpp
parentf1ccc8cdefd29533908a41c73ca156ba45c885fb (diff)
downloadbcm5719-llvm-33afd771b46c29c420cbf8e926330850db36b43a.tar.gz
bcm5719-llvm-33afd771b46c29c420cbf8e926330850db36b43a.zip
Check for duplicate declaration of method of a class
in its extension. llvm-svn: 65854
Diffstat (limited to 'clang/lib/Sema/SemaDeclObjC.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index f1f03844a24..fe26090a174 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -443,6 +443,35 @@ void Sema::MergeProtocolPropertiesIntoClass(Decl *CDecl,
}
}
+/// DiagnoseClassExtensionDupMethods - Check for duplicate declartation of
+/// a class method in its extension.
+///
+void Sema::DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
+ ObjCInterfaceDecl *ID) {
+ if (!ID)
+ return; // Possibly due to previous error
+
+ llvm::DenseMap<Selector, const ObjCMethodDecl*> MethodMap;
+ for (ObjCInterfaceDecl::method_iterator i = ID->meth_begin(),
+ e = ID->meth_end(); i != e; ++i) {
+ ObjCMethodDecl *MD = *i;
+ MethodMap[MD->getSelector()] = MD;
+ }
+
+ if (MethodMap.empty())
+ return;
+ for (ObjCCategoryDecl::method_iterator i = CAT->meth_begin(),
+ e = CAT->meth_end(); i != e; ++i) {
+ ObjCMethodDecl *Method = *i;
+ const ObjCMethodDecl *&PrevMethod = MethodMap[Method->getSelector()];
+ if (PrevMethod && !MatchTwoMethodDeclarations(Method, PrevMethod)) {
+ Diag(Method->getLocation(), diag::err_duplicate_method_decl)
+ << Method->getDeclName();
+ Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
+ }
+ }
+}
+
/// ActOnForwardProtocolDeclaration -
Action::DeclTy *
Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
@@ -1237,6 +1266,8 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
// Merge protocol properties into category
MergeProtocolPropertiesIntoClass(C, C);
+ if (C->getIdentifier() == 0)
+ DiagnoseClassExtensionDupMethods(C, C->getClassInterface());
}
if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(ClassDecl)) {
// ProcessPropertyDecl is responsible for diagnosing conflicts with any
OpenPOWER on IntegriCloud