summaryrefslogtreecommitdiffstats
path: root/clang/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2007-10-16 21:52:23 +0000
committerFariborz Jahanian <fjahanian@apple.com>2007-10-16 21:52:23 +0000
commitebac2cb23561a933f9572a06b0a901c9221f086e (patch)
tree97fe225f6d5931417cb68093b2153cf27139f699 /clang/Sema/SemaDecl.cpp
parentd2754264495998882bc95c7d4a8ca11ecb43b84e (diff)
downloadbcm5719-llvm-ebac2cb23561a933f9572a06b0a901c9221f086e.tar.gz
bcm5719-llvm-ebac2cb23561a933f9572a06b0a901c9221f086e.zip
Patch to diagnose duplicate method implementations.
llvm-svn: 43046
Diffstat (limited to 'clang/Sema/SemaDecl.cpp')
-rw-r--r--clang/Sema/SemaDecl.cpp56
1 files changed, 27 insertions, 29 deletions
diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp
index bb100c67ce4..76d1628bfc2 100644
--- a/clang/Sema/SemaDecl.cpp
+++ b/clang/Sema/SemaDecl.cpp
@@ -1837,6 +1837,7 @@ void Sema::ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *classDecl,
bool checkDuplicateMethods =
(isa<ObjcInterfaceDecl>(ClassDecl) || isa<ObjcCategoryDecl>(ClassDecl)
|| isa<ObjcProtocolDecl>(ClassDecl));
+ bool checkIdenticalMethods = isa<ObjcImplementationDecl>(ClassDecl);
for (unsigned i = 0; i < allNum; i++ ) {
ObjcMethodDecl *Method =
@@ -1844,41 +1845,38 @@ void Sema::ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *classDecl,
if (!Method) continue; // Already issued a diagnostic.
if (Method->isInstance()) {
- if (checkDuplicateMethods) {
- /// Check for instance method of the same name with incompatible types
- const ObjcMethodDecl *&PrevMethod = InsMap[Method->getSelector()];
- if (PrevMethod && !MatchTwoMethodDeclarations(Method, PrevMethod)) {
+ /// Check for instance method of the same name with incompatible types
+ const ObjcMethodDecl *&PrevMethod = InsMap[Method->getSelector()];
+ bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod)
+ : false;
+ if (checkDuplicateMethods && PrevMethod && !match
+ || checkIdenticalMethods && match) {
Diag(Method->getLocation(), diag::error_duplicate_method_decl,
Method->getSelector().getName());
Diag(PrevMethod->getLocation(), diag::err_previous_declaration);
- } else {
- insMethods.push_back(Method);
- InsMap[Method->getSelector()] = Method;
- }
- }
- else
+ } else {
insMethods.push_back(Method);
-
- /// The following allows us to typecheck messages to "id".
- AddInstanceMethodToGlobalPool(Method);
- } else {
- if (checkDuplicateMethods) {
- /// Check for class method of the same name with incompatible types
- const ObjcMethodDecl *&PrevMethod = ClsMap[Method->getSelector()];
- if (PrevMethod && !MatchTwoMethodDeclarations(Method, PrevMethod)) {
- Diag(Method->getLocation(), diag::error_duplicate_method_decl,
- Method->getSelector().getName());
- Diag(PrevMethod->getLocation(), diag::err_previous_declaration);
- } else {
- clsMethods.push_back(Method);
- ClsMap[Method->getSelector()] = Method;
- }
+ InsMap[Method->getSelector()] = Method;
+ /// The following allows us to typecheck messages to "id".
+ AddInstanceMethodToGlobalPool(Method);
}
- else
+ }
+ else {
+ /// Check for class method of the same name with incompatible types
+ const ObjcMethodDecl *&PrevMethod = ClsMap[Method->getSelector()];
+ bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod)
+ : false;
+ if (checkDuplicateMethods && PrevMethod && !match
+ || checkIdenticalMethods && match) {
+ Diag(Method->getLocation(), diag::error_duplicate_method_decl,
+ Method->getSelector().getName());
+ Diag(PrevMethod->getLocation(), diag::err_previous_declaration);
+ } else {
clsMethods.push_back(Method);
-
- /// The following allows us to typecheck messages to "id".
- AddFactoryMethodToGlobalPool(Method);
+ ClsMap[Method->getSelector()] = Method;
+ /// The following allows us to typecheck messages to "id".
+ AddInstanceMethodToGlobalPool(Method);
+ }
}
}
OpenPOWER on IntegriCloud