[cfe-commits] r146504 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp test/Parser/enhanced-proto-1.m test/SemaObjC/DoubleMethod.m test/SemaObjC/check-dup-decl-methods-1.m test/SemaObjC/class-conforming-protocol-1.m test/SemaObjC/enhanced-proto-2.m test/SemaObjC/undefined-protocol-type-1.m

Fariborz Jahanian fjahanian at apple.com
Tue Dec 13 11:40:35 PST 2011


Author: fjahanian
Date: Tue Dec 13 13:40:34 2011
New Revision: 146504

URL: http://llvm.org/viewvc/llvm-project?rev=146504&view=rev
Log:
objc: diagnose duplicate declaration of methods
in classes. // rdar://10535349

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/Parser/enhanced-proto-1.m
    cfe/trunk/test/SemaObjC/DoubleMethod.m
    cfe/trunk/test/SemaObjC/check-dup-decl-methods-1.m
    cfe/trunk/test/SemaObjC/class-conforming-protocol-1.m
    cfe/trunk/test/SemaObjC/enhanced-proto-2.m
    cfe/trunk/test/SemaObjC/undefined-protocol-type-1.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=146504&r1=146503&r2=146504&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Dec 13 13:40:34 2011
@@ -174,6 +174,7 @@
 def InvalidOffsetof : DiagGroup<"invalid-offsetof">;
 def : DiagGroup<"strict-prototypes">;
 def StrictSelector : DiagGroup<"strict-selector-match">;
+def MethodDuplicate : DiagGroup<"duplicate-method-match">;
 def SwitchEnum     : DiagGroup<"switch-enum">;
 def Switch         : DiagGroup<"switch", [SwitchEnum]>;
 def Trigraphs      : DiagGroup<"trigraphs">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=146504&r1=146503&r2=146504&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 13 13:40:34 2011
@@ -488,6 +488,9 @@
 def note_method_declared_at : Note<"method declared here">;
 def err_setter_type_void : Error<"type of setter must be void">;
 def err_duplicate_method_decl : Error<"duplicate declaration of method %0">;
+def warn_duplicate_method_decl : 
+  Warning<"multiple declarations of method %0 found and ignored">, 
+  InGroup<MethodDuplicate>;
 def err_objc_var_decl_inclass : 
     Error<"cannot declare variable inside @interface or @protocol">;
 def error_missing_method_context : Error<

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=146504&r1=146503&r2=146504&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Dec 13 13:40:34 2011
@@ -2210,8 +2210,14 @@
           Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
         Method->setInvalidDecl();
       } else {
-        if (PrevMethod)
+        if (PrevMethod) {
           Method->setAsRedeclaration(PrevMethod);
+          if (!Context.getSourceManager().isInSystemHeader(
+                 Method->getLocation()))
+            Diag(Method->getLocation(), diag::warn_duplicate_method_decl)
+              << Method->getDeclName();
+          Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
+        }
         InsMap[Method->getSelector()] = Method;
         /// The following allows us to typecheck messages to "id".
         AddInstanceMethodToGlobalPool(Method);
@@ -2231,8 +2237,14 @@
         Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
         Method->setInvalidDecl();
       } else {
-        if (PrevMethod)
+        if (PrevMethod) {
           Method->setAsRedeclaration(PrevMethod);
+          if (!Context.getSourceManager().isInSystemHeader(
+                 Method->getLocation()))
+            Diag(Method->getLocation(), diag::warn_duplicate_method_decl)
+              << Method->getDeclName();
+          Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
+        }
         ClsMap[Method->getSelector()] = Method;
         /// The following allows us to typecheck messages to "Class".
         AddFactoryMethodToGlobalPool(Method);

Modified: cfe/trunk/test/Parser/enhanced-proto-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/enhanced-proto-1.m?rev=146504&r1=146503&r2=146504&view=diff
==============================================================================
--- cfe/trunk/test/Parser/enhanced-proto-1.m (original)
+++ cfe/trunk/test/Parser/enhanced-proto-1.m Tue Dec 13 13:40:34 2011
@@ -4,7 +4,7 @@
 @optional
 - (void) FOO;
 @optional
-- (void) FOO;
+- (void) FOO1;
 @required 
 - (void) REQ;
 @optional

Modified: cfe/trunk/test/SemaObjC/DoubleMethod.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/DoubleMethod.m?rev=146504&r1=146503&r2=146504&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/DoubleMethod.m (original)
+++ cfe/trunk/test/SemaObjC/DoubleMethod.m Tue Dec 13 13:40:34 2011
@@ -5,8 +5,8 @@
     int ivar;
 }
 
-- (void) method;
-- (void) method;
+- (void) method; // expected-note {{previous declaration is here}}
+- (void) method; // expected-warning {{multiple declarations of method 'method' found and ignored}}
 @end
 
 @implementation Subclass

Modified: cfe/trunk/test/SemaObjC/check-dup-decl-methods-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/check-dup-decl-methods-1.m?rev=146504&r1=146503&r2=146504&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/check-dup-decl-methods-1.m (original)
+++ cfe/trunk/test/SemaObjC/check-dup-decl-methods-1.m Tue Dec 13 13:40:34 2011
@@ -10,8 +10,8 @@
 @interface class1 : SUPER
 - (int) meth;	// expected-note {{previous declaration is here}}
 - (int*) meth;	// expected-error {{duplicate declaration of method 'meth'}}
-- (T*) meth1;  
-- (T*) meth1;
+- (T*) meth1;   // expected-note {{previous declaration is here}}
+- (T*) meth1;   // expected-warning {{multiple declarations of method 'meth1' found and ignored}}
 + (T*) meth1;
 @end
 

Modified: cfe/trunk/test/SemaObjC/class-conforming-protocol-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-conforming-protocol-1.m?rev=146504&r1=146503&r2=146504&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/class-conforming-protocol-1.m (original)
+++ cfe/trunk/test/SemaObjC/class-conforming-protocol-1.m Tue Dec 13 13:40:34 2011
@@ -8,12 +8,11 @@
 - (INTF*) METH1;	// expected-note {{previous declaration is here}}
 - (INTF<P1>*) METH1;	// expected-error {{duplicate declaration of method 'METH1'}}
 
-- (INTF<P1,P2>*) METH2;
 - (INTF<P2,P1>*) METH2;  // expected-note {{previous declaration is here}}
 - (INTF<P2,P1,P3>*) METH2;  // expected-error {{duplicate declaration of method 'METH2'}}
 
-- (INTF<P2,P1,P3>*) METH3;
-- (INTF<P3,P1,P2, P3>*) METH3;
+- (INTF<P2,P1,P3>*) METH3; // expected-note {{previous declaration is here}}
+- (INTF<P3,P1,P2, P3>*) METH3; // expected-warning {{multiple declarations of method 'METH3' found and ignored}}
 
 @end
 

Modified: cfe/trunk/test/SemaObjC/enhanced-proto-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/enhanced-proto-2.m?rev=146504&r1=146503&r2=146504&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/enhanced-proto-2.m (original)
+++ cfe/trunk/test/SemaObjC/enhanced-proto-2.m Tue Dec 13 13:40:34 2011
@@ -4,7 +4,7 @@
 @optional
 - (void) FOO;
 @optional
-- (void) FOO;
+- (void) FOO1;
 @optional 
 - (void) REQ;
 @optional

Modified: cfe/trunk/test/SemaObjC/undefined-protocol-type-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/undefined-protocol-type-1.m?rev=146504&r1=146503&r2=146504&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/undefined-protocol-type-1.m (original)
+++ cfe/trunk/test/SemaObjC/undefined-protocol-type-1.m Tue Dec 13 13:40:34 2011
@@ -5,5 +5,5 @@
 
 @interface T
 - (T<p2, p3, p1, p4>*) meth;  // expected-error {{cannot find protocol declaration for 'p3'}}
-- (T<p2, p3, p1, p4>*) meth;  // expected-error {{cannot find protocol declaration for 'p3'}}
+- (T<p2, p3, p1, p4>*) meth1;  // expected-error {{cannot find protocol declaration for 'p3'}}
 @end





More information about the cfe-commits mailing list