]> granicus.if.org Git - clang/commitdiff
Objective-C. Diagose use of undefined protocols
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 11 Mar 2014 17:10:51 +0000 (17:10 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 11 Mar 2014 17:10:51 +0000 (17:10 +0000)
when a class adopts a protocol that inherits from
undefined protocols. // rdar://16111182

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203586 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclObjC.cpp
test/Analysis/region-1.m
test/SemaObjC/category-1.m
test/SemaObjC/class-def-test-1.m
test/SemaObjC/class-proto-1.m

index c9bdcf12cb6ab30343f031ad7dab53ec0835cead..4f93429a8406a1d63a9b154de2db9bfafc4dcd6b 100644 (file)
@@ -2485,6 +2485,8 @@ def warn_objc_requires_super_protocol : Warning<
   InGroup<DiagGroup<"requires-super-attribute">>;
 def note_protocol_decl : Note<
   "protocol is declared here">;
+def note_protocol_decl_undefined : Note<
+  "protocol %0 has no definition">;
 
 // objc_designated_initializer attribute diagnostics.
 def warn_objc_designated_init_missing_super_call : Warning<
index e19432aea97e89a3a024ee498c41dd44affbe6a6..4de290b3eb8cc6b48ab9564f4260745961bfcc9e 100644 (file)
@@ -760,6 +760,22 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
   return ActOnObjCContainerStartDefinition(PDecl);
 }
 
+static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl,
+                                          ObjCProtocolDecl *&UndefinedProtocol) {
+  if (!PDecl->hasDefinition() || PDecl->getDefinition()->isHidden()) {
+    UndefinedProtocol = PDecl;
+    return true;
+  }
+  
+  for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
+       E = PDecl->protocol_end(); PI != E; ++PI)
+    if (NestedProtocolHasNoDefinition((*PI), UndefinedProtocol)) {
+      UndefinedProtocol = (*PI);
+      return true;
+    }
+  return false;
+}
+
 /// FindProtocolDeclaration - This routine looks up protocols and
 /// issues an error if they are not declared. It returns list of
 /// protocol declarations in its 'Protocols' argument.
@@ -795,10 +811,15 @@ Sema::FindProtocolDeclaration(bool WarnOnDeclarations,
     // If this is a forward declaration and we are supposed to warn in this
     // case, do it.
     // FIXME: Recover nicely in the hidden case.
+    ObjCProtocolDecl *UndefinedProtocol;
+    
     if (WarnOnDeclarations &&
-        (!PDecl->hasDefinition() || PDecl->getDefinition()->isHidden()))
+        NestedProtocolHasNoDefinition(PDecl, UndefinedProtocol)) {
       Diag(ProtocolId[i].second, diag::warn_undef_protocolref)
         << ProtocolId[i].first;
+      Diag(UndefinedProtocol->getLocation(), diag::note_protocol_decl_undefined)
+        << UndefinedProtocol;
+    }
     Protocols.push_back(PDecl);
   }
 }
index 9edb35b78b7c4410cdcbdb505bd718ea83f252d3..6940c69dc1bc3f5aa4a30bb2c666dc26c8b4dbe2 100644 (file)
@@ -25,7 +25,7 @@ typedef unsigned int NSUInteger;
 CK_UNRESTRICTED= 0,     CK_READ_ONLY,     CK_ADD_ONLY,     CK_REMOVE_ONLY };
 @protocol EcoClass <EcoBehavioredClassifier>      - (NSArray *) ownedAttributes;
 @end @protocol EcoNamespace;
-@protocol EcoType;
+@protocol EcoType @end;
 @protocol EcoClassifier <EcoNamespace,EcoType>    - (NSArray *) features; 
 @end @protocol EcoComment;
 @protocol EcoElement <NSObject> - (NSArray *) ownedElements;
index 3c2f7d0032a0d1b0052c9ecda6a723618ee795d6..89ac550578c57f5eaa029f15c79255c08dc3b111 100644 (file)
@@ -2,7 +2,8 @@
 
 @interface MyClass1 @end
 
-@protocol p1,p2,p3;
+@protocol p1,p2,p3; // expected-note {{protocol 'p1' has no definition}} \
+                    // expected-note {{protocol 'p2' has no definition}}
 
 @interface MyClass1 (Category1)  <p1> // expected-warning {{cannot find protocol definition for 'p1'}} expected-note {{previous definition is here}}
 @end
index 7931cc3fdce49f8e597d96126482e03e5795e5e4..98a887ecab1f6c5767d7cfac89fbeceb72b4ab56 100644 (file)
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
 
-@protocol SUPER;
+@protocol SUPER; // expected-note {{protocol 'SUPER' has no definition}}
 
 @interface SUPER <SUPER> @end // expected-warning {{cannot find protocol definition for 'SUPER'}}
 
index 02c40aab65995e3c7807ca0424261ee63b3144f1..51a899341e31c95894ae5d3d7495e49f07afe77e 100644 (file)
@@ -2,7 +2,8 @@
 
 @interface INTF1 @end
 
-@protocol p1,p2,p3;
+@protocol p1,p2,p3; // expected-note {{protocol 'p2' has no definition}} \
+                    // expected-note {{protocol 'p3' has no definition}}
 
 @protocol p1;
 
 
 @interface I4 : U2 <p1,p2>
 @end
+
+// rdar://16111182
+@interface NSObject @end
+
+@protocol UndefinedParentProtocol; // expected-note {{protocol 'UndefinedParentProtocol' has no definition}}
+
+@protocol UndefinedProtocol <UndefinedParentProtocol>
+@end
+
+@interface SomeObject : NSObject <UndefinedProtocol> // expected-warning {{cannot find protocol definition for 'UndefinedProtocol'}}
+@end