[cfe-commits] r43046 - in /cfe/trunk: Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj test/Sema/DoubleMethod.m

Fariborz Jahanian fjahanian at apple.com
Tue Oct 16 14:52:23 PDT 2007


Author: fjahanian
Date: Tue Oct 16 16:52:23 2007
New Revision: 43046

URL: http://llvm.org/viewvc/llvm-project?rev=43046&view=rev
Log:
Patch to diagnose duplicate method implementations.

Added:
    cfe/trunk/test/Sema/DoubleMethod.m
Modified:
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Oct 16 16:52:23 2007
@@ -1837,6 +1837,7 @@
   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 @@
 
     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);
+      }
     }
   }
   

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=43046&r1=43045&r2=43046&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Oct 16 16:52:23 2007
@@ -238,7 +238,7 @@
 		84AF36A00CB17A3B00C820A5 /* DeclObjC.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DeclObjC.h; path = clang/AST/DeclObjC.h; sourceTree = "<group>"; };
 		84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = "<group>"; };
 		84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; };
-		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
 		DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
 		DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
 		DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };

Added: cfe/trunk/test/Sema/DoubleMethod.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/DoubleMethod.m?rev=43046&view=auto

==============================================================================
--- cfe/trunk/test/Sema/DoubleMethod.m (added)
+++ cfe/trunk/test/Sema/DoubleMethod.m Tue Oct 16 16:52:23 2007
@@ -0,0 +1,19 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface Subclass
+{
+    int ivar;
+}
+
+- (void) method;
+- (void) method;
+ at end
+
+ at implementation Subclass
+- (void) method {;} // expected-error {{previous declaration is here}}
+- (void) method {;} // expected-error {{duplicate declaration of method 'method'}}
+ at end
+
+int main (void) {
+    return 0;
+}





More information about the cfe-commits mailing list