[cfe-commits] r42938 - in /cfe/trunk: Sema/SemaDecl.cpp test/Sema/check-dup-decl-methods-1.m

Fariborz Jahanian fjahanian at apple.com
Fri Oct 12 16:43:31 PDT 2007


Author: fjahanian
Date: Fri Oct 12 18:43:31 2007
New Revision: 42938

URL: http://llvm.org/viewvc/llvm-project?rev=42938&view=rev
Log:
Patch to check for duplicate method decls in protocols.

Modified:
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/check-dup-decl-methods-1.m

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42938&r1=42937&r2=42938&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Oct 12 18:43:31 2007
@@ -1768,15 +1768,16 @@
   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 @@
         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)) {

Modified: cfe/trunk/test/Sema/check-dup-decl-methods-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/check-dup-decl-methods-1.m?rev=42938&r1=42937&r2=42938&view=diff

==============================================================================
--- cfe/trunk/test/Sema/check-dup-decl-methods-1.m (original)
+++ cfe/trunk/test/Sema/check-dup-decl-methods-1.m Fri Oct 12 18:43:31 2007
@@ -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
 





More information about the cfe-commits mailing list