]> granicus.if.org Git - clang/commitdiff
Patch to check for duplicate method decls in protocols.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 12 Oct 2007 23:43:31 +0000 (23:43 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 12 Oct 2007 23:43:31 +0000 (23:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42938 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaDecl.cpp
test/Sema/check-dup-decl-methods-1.m

index b66c9f4860d5e89f94c15fe20160839ec7b1aebd..e7b717c59c0df058e0b49b9c0bf77eeea799287c 100644 (file)
@@ -1768,15 +1768,16 @@ void Sema::ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *classDecl,
   llvm::DenseMap<Selector, const ObjcMethodDecl*> InsMap;
   llvm::DenseMap<Selector, const ObjcMethodDecl*> ClsMap;
   
-  bool isClassDeclaration = 
-        (isa<ObjcInterfaceDecl>(ClassDecl) || isa<ObjcCategoryDecl>(ClassDecl));
+  bool checkDuplicateMethods = 
+        (isa<ObjcInterfaceDecl>(ClassDecl) || isa<ObjcCategoryDecl>(ClassDecl)
+         || isa<ObjcProtocolDecl>(ClassDecl));
   
   for (unsigned i = 0; i < allNum; i++ ) {
     ObjcMethodDecl *Method =
       cast_or_null<ObjcMethodDecl>(static_cast<Decl*>(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)) {
index d69c4a71007d195e61398db546fcb91c1bbd9252..36a98a24a462d60a93e3768cd3dcbd4b9ec5a25d 100644 (file)
@@ -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