From: Fariborz Jahanian Date: Fri, 12 Oct 2007 23:43:31 +0000 (+0000) Subject: Patch to check for duplicate method decls in protocols. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1109b42c036029c6ac49500af06efc15a627f5e8;p=clang Patch to check for duplicate method decls in protocols. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42938 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index b66c9f4860..e7b717c59c 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -1768,15 +1768,16 @@ void Sema::ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *classDecl, llvm::DenseMap InsMap; llvm::DenseMap ClsMap; - bool isClassDeclaration = - (isa(ClassDecl) || isa(ClassDecl)); + bool checkDuplicateMethods = + (isa(ClassDecl) || isa(ClassDecl) + || isa(ClassDecl)); for (unsigned i = 0; i < allNum; i++ ) { ObjcMethodDecl *Method = cast_or_null(static_cast(allMethods[i])); if (!Method) continue; // Already issued a diagnostic. if (Method->isInstance()) { - if (isClassDeclaration) { + if (checkDuplicateMethods) { /// Check for instance method of the same name with incompatible types const ObjcMethodDecl *&PrevMethod = InsMap[Method->getSelector()]; if (PrevMethod && !MatchTwoMethodDeclarations(Method, PrevMethod)) { @@ -1793,7 +1794,7 @@ void Sema::ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *classDecl, insMethods.push_back(Method); } else { - if (isClassDeclaration) { + if (checkDuplicateMethods) { /// Check for class method of the same name with incompatible types const ObjcMethodDecl *&PrevMethod = ClsMap[Method->getSelector()]; if (PrevMethod && !MatchTwoMethodDeclarations(Method, PrevMethod)) { diff --git a/test/Sema/check-dup-decl-methods-1.m b/test/Sema/check-dup-decl-methods-1.m index d69c4a7100..36a98a24a4 100644 --- a/test/Sema/check-dup-decl-methods-1.m +++ b/test/Sema/check-dup-decl-methods-1.m @@ -32,7 +32,7 @@ @end @protocol P -- (int) meth; -- (int*) meth; +- (int) meth; // expected-error {{previous declaration is here}} +- (int*) meth; // expected-error {{duplicate declaration of method 'meth'}} @end