]> granicus.if.org Git - clang/commitdiff
Improve diagnostics on incomplete implementation
authorFariborz Jahanian <fjahanian@apple.com>
Sat, 27 Mar 2010 19:02:17 +0000 (19:02 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Sat, 27 Mar 2010 19:02:17 +0000 (19:02 +0000)
of objc classes; including which methods
need be implemented and where they come from.
WIP.

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

13 files changed:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclObjC.cpp
test/Analysis/PR3991.m
test/Analysis/pr4209.m
test/SemaObjC/category-1.m
test/SemaObjC/compare-qualified-id.m
test/SemaObjC/conditional-expr.m
test/SemaObjC/gcc-cast-ext.m
test/SemaObjC/method-arg-decay.m
test/SemaObjC/method-undef-category-warn-1.m
test/SemaObjC/method-undef-extension-warn-1.m
test/SemaObjC/method-undefined-warn-1.m
test/SemaObjC/undef-protocol-methods-1.m

index c6f20247fa8488026fc111d8bcfc701ba619426f..a8bca592dfea51e94503c32d47e6cc4ea1838341 100644 (file)
@@ -275,7 +275,9 @@ def err_conflicting_ivar_name : Error<
 def err_inconsistant_ivar_count : Error<
   "inconsistent number of instance variables specified">;
 def warn_incomplete_impl : Warning<"incomplete implementation">;
-def warn_undef_method_impl : Warning<"method definition for %0 not found">;
+def note_undef_method_impl : Note<"method definition for %0 not found">;
+def note_required_for_protocol_at : 
+  Note<"required for direct or indirect protocol %0">;
 
 def warn_conflicting_ret_types : Warning<
   "conflicting return type in implementation of %0: %1 vs %2">;
index 1feeffdfe50aee19910a3f5ede0a6f6721ee9643..79a664f2e1f8f6807f75e7e429bf2db1200eb830 100644 (file)
@@ -724,7 +724,8 @@ void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
     Diag(ImpLoc, diag::warn_incomplete_impl);
     IncompleteImpl = true;
   }
-  Diag(ImpLoc, diag::warn_undef_method_impl) << method->getDeclName();
+  Diag(method->getLocation(), diag::note_undef_method_impl) 
+    << method->getDeclName();
 }
 
 void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
@@ -806,8 +807,11 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc,
             // uses the protocol.
             ObjCMethodDecl *MethodInClass =
             IDecl->lookupInstanceMethod(method->getSelector());
-            if (!MethodInClass || !MethodInClass->isSynthesized())
+            if (!MethodInClass || !MethodInClass->isSynthesized()) {
               WarnUndefinedMethod(ImpLoc, method, IncompleteImpl);
+              Diag(IDecl->getLocation(), diag::note_required_for_protocol_at) <<
+                PDecl->getDeclName();
+            }
           }
     }
   // check unimplemented class methods
@@ -817,8 +821,11 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc,
     ObjCMethodDecl *method = *I;
     if (method->getImplementationControl() != ObjCMethodDecl::Optional &&
         !ClsMap.count(method->getSelector()) &&
-        (!Super || !Super->lookupClassMethod(method->getSelector())))
+        (!Super || !Super->lookupClassMethod(method->getSelector()))) {
       WarnUndefinedMethod(ImpLoc, method, IncompleteImpl);
+      Diag(IDecl->getLocation(), diag::note_required_for_protocol_at) <<
+        PDecl->getDeclName();
+    }
   }
   // Check on this protocols's referenced protocols, recursively.
   for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
index 3fed57e11285d2e33fa7cddd18ef650cb6527ea8..c1f238c77c854e9a3b91e4cabc004bd1a85cea07 100644 (file)
@@ -35,22 +35,16 @@ typedef struct _NSZone NSZone;
 @protocol IHGoogleDocsAdapterDelegate  - (void)googleDocsAdapter:(IHGoogleDocsAdapter*)inGoogleDocsAdapter accountVerifyIsValid:(BOOL)inIsValid error:(NSError *)inError;
 @end   @interface IHGoogleDocsAdapter : NSObject {
 }
-- (NSArray *)entries;
+- (NSArray *)entries; // expected-note {{method definition for 'entries' not found}}
 @end extern Class const kGDataUseRegisteredClass ;
-@interface IHGoogleDocsAdapter ()  - (GDataFeedDocList *)feedDocList;
-- (NSArray *)directoryPathComponents;
-- (unsigned int)currentPathComponentIndex;
-- (void)setCurrentPathComponentIndex:(unsigned int)aCurrentPathComponentIndex;
-- (NSURL *)folderFeedURL;
+@interface IHGoogleDocsAdapter ()  - (GDataFeedDocList *)feedDocList; // expected-note {{method definition for 'feedDocList' not found}}
+- (NSArray *)directoryPathComponents; // expected-note {{method definition for 'directoryPathComponents' not found}}
+- (unsigned int)currentPathComponentIndex; // expected-note {{method definition for 'currentPathComponentIndex' not found}}
+- (void)setCurrentPathComponentIndex:(unsigned int)aCurrentPathComponentIndex; // expected-note {{method definition for 'setCurrentPathComponentIndex:' not found}}
+- (NSURL *)folderFeedURL; // expected-note {{method definition for 'folderFeedURL' not found}}
 @end  
 
-@implementation IHGoogleDocsAdapter    - (id)initWithUsername:(NSString *)inUsername password:(NSString *)inPassword owner:(NSObject <IHGoogleDocsAdapterDelegate> *)owner {   // expected-warning {{incomplete implementation}} \
-// expected-warning {{method definition for 'entries' not found}} \
-// expected-warning {{method definition for 'feedDocList' not found}} \
-// expected-warning {{method definition for 'directoryPathComponents' not found}} \
-// expected-warning {{method definition for 'currentPathComponentIndex' not found}} \
-// expected-warning {{method definition for 'setCurrentPathComponentIndex:' not found}} \
-// expected-warning {{method definition for 'folderFeedURL' not found}} 
+@implementation IHGoogleDocsAdapter    - (id)initWithUsername:(NSString *)inUsername password:(NSString *)inPassword owner:(NSObject <IHGoogleDocsAdapterDelegate> *)owner {   // expected-warning {{incomplete implementation}}
   return 0;
 }
 
index eb010157d661cb18a9633c3d0e9873e3e152b930..dc1ef7b9997f5102cae453077ae46dd75d1376f8 100644 (file)
@@ -48,16 +48,14 @@ CMProfileLocation;
 @interface GBCategoryChooserPanelController : NSWindowController {
   GSEbayCategory *rootCategory;
 }
-- (NSMutableDictionary*)categoryDictionaryForCategoryID:(int)inID inRootTreeCategories:(NSMutableArray*)inRootTreeCategories;
--(NSString*) categoryID; 
+- (NSMutableDictionary*)categoryDictionaryForCategoryID:(int)inID inRootTreeCategories:(NSMutableArray*)inRootTreeCategories; // expected-note {{method definition for 'categoryDictionaryForCategoryID:inRootTreeCategories:' not found}}
+-(NSString*) categoryID;  // expected-note {{method definition for 'categoryID' not found}}
 @end @interface GSEbayCategory : NSObject <NSCoding> {
 }
 - (int) categoryID;
 - (GSEbayCategory *) parent;
 - (GSEbayCategory*) subcategoryWithID:(int) inID;
-@end   @implementation GBCategoryChooserPanelController  + (int) chooseCategoryIDFromCategories:(NSArray*) inCategories        searchRequest:(GBSearchRequest*)inRequest         parentWindow:(NSWindow*) inParent { // expected-warning {{incomplete implementation}} \
-// expected-warning {{method definition for 'categoryDictionaryForCategoryID:inRootTreeCategories:' not found}} \
-// expected-warning {{method definition for 'categoryID' not found}}
+@end   @implementation GBCategoryChooserPanelController  + (int) chooseCategoryIDFromCategories:(NSArray*) inCategories        searchRequest:(GBSearchRequest*)inRequest         parentWindow:(NSWindow*) inParent { // expected-warning {{incomplete implementation}}
   return 0;
 }
 - (void) addCategory:(EBayCategoryType*)inCategory toRootTreeCategory:(NSMutableArray*)inRootTreeCategories {
index 24324f8500afd5ec9a637fc6e0be7e5cb9ea9bf1..bf2aa53e8ffcedcded3229ac36c8ff88fbd79b53 100644 (file)
 // <rdar://problem/7249233>
 
 @protocol MultipleCat_P
--(void) im0;
+-(void) im0; // expected-note {{method definition for 'im0' not found}}
 @end
 
-@interface MultipleCat_I @end
+@interface MultipleCat_I @end // expected-note {{required for direct or indirect protocol 'MultipleCat_P'}}
 
 @interface MultipleCat_I()  @end
 
 @interface MultipleCat_I() <MultipleCat_P>  @end
 
-@implementation MultipleCat_I // expected-warning {{incomplete implementation}}, expected-warning {{method definition for 'im0' not found}}
+@implementation MultipleCat_I // expected-warning {{incomplete implementation}}
 @end
 
 // <rdar://problem/7680391> - Handle nameless categories with no name that refer
index 497a1b6afdca840c64be1893f438d28758e2fab7..f4ec2540287eb2a0e95b707c3552638879aa1289 100644 (file)
@@ -5,7 +5,7 @@ typedef unsigned int NSUInteger;
 typedef struct _NSZone NSZone;
 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
 @protocol NSObject  - (BOOL)isEqual:(id)object; @end
-@protocol NSCopying  - (id)copyWithZone:(NSZone *)zone; @end
+@protocol NSCopying  - (id)copyWithZone:(NSZone *)zone; @end // expected-note {{method definition for 'copyWithZone:' not found}}
 @protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone; @end
 @protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder; @end
 @interface NSObject <NSObject> {} @end
@@ -15,7 +15,7 @@ typedef struct {} NSFastEnumerationState;
 @interface NSMutableDictionary : NSDictionary  - (void)removeObjectForKey:(id)aKey; @end
 extern NSString * const NSTaskDidTerminateNotification;
 
-@interface XCPropertyExpansionContext : NSObject <NSCopying> {
+@interface XCPropertyExpansionContext : NSObject <NSCopying> { // expected-note {{required for direct or indirect protocol 'NSCopying'}}
   NSMutableDictionary * _propNamesToPropValuesCache;
 } @end
 
@@ -23,8 +23,7 @@ extern NSString * const NSTaskDidTerminateNotification;
 - (NSString *)evaluateAsStringInContext:(XCPropertyExpansionContext *)context withNestingState:(const void *)state;
 @end
 
-@implementation XCPropertyExpansionContext     // expected-warning {{method definition for 'copyWithZone:' not found}} \
-                                               // expected-warning {{incomplete implementation}}
+@implementation XCPropertyExpansionContext // expected-warning {{incomplete implementation}}
 - (NSString *)expandedValueForProperty:(NSString *)property {
   id <XCPropertyValues> cachedValueNode = [_propNamesToPropValuesCache objectForKey:property]; // expected-warning {{method '-objectForKey:' not found (return type defaults to 'id')}}
   if (cachedValueNode == ((void *)0)) { }
index 914e3cabbf01f1afa5ac4103384fe232e9ec00c8..1436f7ee0e001d64fd97ef461b009ff9e7eb0834 100644 (file)
 @end
 
 @interface DTFilterOutputStream2
-- nextOutputStream;
+- nextOutputStream; // expected-note {{{{method definition for 'nextOutputStream' not found}}
 @end
 
-@implementation DTFilterOutputStream2 // expected-warning {{incomplete implementation}} expected-warning {{method definition for 'nextOutputStream' not found}}
+@implementation DTFilterOutputStream2 // expected-warning {{incomplete implementation}}
 - (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
   id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
   self = nextOutputStream; // expected-warning {{incompatible type assigning 'id<DTOutputStreams>', expected 'DTFilterOutputStream2 *'}}
index 28abfbc8b2abd7b65d7f93798f842e75740ef162..599e37d77839a9338fc100787c12073868c1b366 100644 (file)
@@ -5,8 +5,8 @@ typedef struct _NSRange { } NSRange;
 @class PBXFileReference;
 
 @interface PBXDocBookmark
-+ alloc;
-- autorelease;
++ alloc;       // expected-note {{{{method definition for 'alloc' not found}}
+- autorelease; // expected-note {{{{method definition for 'autorelease' not found}}
 @end
 
 // GCC allows pointer expressions in integer constant expressions.
@@ -14,7 +14,7 @@ struct {
   char control[((int)(char *)2)];
 } xx;
 
-@implementation PBXDocBookmark  // expected-warning {{incomplete implementation}} expected-warning {{method definition for 'autorelease' not found}} expected-warning {{method definition for 'alloc' not found}}
+@implementation PBXDocBookmark  // expected-warning {{incomplete implementation}}
 
 + (id)bookmarkWithFileReference:(PBXFileReference *)fileRef gylphRange:(NSRange)range anchor:(NSString *)htmlAnchor
 {
index f600029fda7be9cd1a3cf9d554388efa087b5af9..e62e7f3d18fd17810972288a8b602d461556bba7 100644 (file)
@@ -56,7 +56,7 @@ PBXFindMatchContains,     PBXFindMatchStartsWith,     PBXFindMatchWholeWords,
 @interface PBXProjectModule : PBXModule <PBXFindableText> {
 }
 @end @class PBXBookmark;
-@protocol PBXSelectionTarget - (NSObject <PBXSelectionTarget> *) performAction:(id)action withSelection:(NSArray *)selection;
+@protocol PBXSelectionTarget - (NSObject <PBXSelectionTarget> *) performAction:(id)action withSelection:(NSArray *)selection; // expected-note {{method definition for 'performAction:withSelection:' not found}}
 @end @class XCPropertyDictionary, XCPropertyCondition, XCPropertyConditionSet, XCMutablePropertyConditionSet;
 extern NSMutableArray *XCFindPossibleKeyModules(PBXModule *module, BOOL useExposedModulesOnly);
 @interface NSString (StringUtilities) - (NSString *) trimToLength:(NSInteger)length preserveRange:(NSRange)range;
@@ -67,14 +67,12 @@ extern NSMutableArray *XCFindPossibleKeyModules(PBXModule *module, BOOL useExpos
 @interface XCExtendedTabView : NSTabView <XCDockViewHeader> {
 }
 @end     @class PBXProjectDocument, PBXFileReference, PBXModule, XCWindowTool;
-@interface XCPerspectiveModule : PBXProjectModule <PBXSelectionTarget> {
+@interface XCPerspectiveModule : PBXProjectModule <PBXSelectionTarget> { // expected-note {{required for direct or indirect protocol 'PBXSelectionTarget'}}
   XCExtendedTabView *_perspectivesTabView;
 }
-- (PBXModule *) moduleForTab:(NSTabViewItem *)item;
+- (PBXModule *) moduleForTab:(NSTabViewItem *)item; // expected-note {{method definition for 'moduleForTab:' not found}}
 @end  
-@implementation XCPerspectiveModule    // expected-warning {{method definition for 'moduleForTab:' not found}} \
-                                       // expected-warning {{method definition for 'performAction:withSelection:' not found}} \
-                                       // expected-warning {{incomplete implementation}}
+@implementation XCPerspectiveModule // expected-warning {{incomplete implementation}}
 + (void) openForProjectDocument:(PBXProjectDocument *)projectDocument {
 }
 - (PBXModule *) type:(Class)type inPerspective:(id)perspectiveIdentifer  matchingFunction:(BOOL (void *, void *))comparator usingData:(void *)data {
index 75ca5b5ff9fb8695f198778c3878edef76d69f53..dace8ab2949bd37755720130251f5f628dcc3321 100644 (file)
@@ -1,30 +1,26 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
-@interface MyClass1 
+@interface MyClass1  // expected-note 2 {{required for direct or indirect protocol 'P'}}
 @end
 
 @protocol P
-- (void) Pmeth;        
-- (void) Pmeth1;  
+- (void) Pmeth;         // expected-note {{method definition for 'Pmeth' not found}}
+- (void) Pmeth1;   // expected-note {{method definition for 'Pmeth1' not found}}
 @end
 
 @interface MyClass1(CAT) <P>
-- (void) meth2;        
+- (void) meth2;         // expected-note {{method definition for 'meth2' not found}}
 @end
 
-@implementation MyClass1(CAT) // expected-warning {{incomplete implementation}} \
-                                 expected-warning {{method definition for 'meth2' not found}} \
-                                 expected-warning {{method definition for 'Pmeth' not found}}
+@implementation MyClass1(CAT) // expected-warning {{incomplete implementation}} 
 - (void) Pmeth1{}
 @end
 
 @interface MyClass1(DOG) <P>
-- (void)ppp;   
+- (void)ppp;    // expected-note {{method definition for 'ppp' not found}}
 @end
 
-@implementation MyClass1(DOG) // expected-warning {{incomplete implementation}} \
-                                 expected-warning {{method definition for 'ppp' not found}} \
-                                 expected-warning {{method definition for 'Pmeth1' not found}}
+@implementation MyClass1(DOG) // expected-warning {{incomplete implementation}}
 - (void) Pmeth {}
 @end
 
index fc27870f42dd7618845ae38dd1cc800c0fd0bea2..cd31754037cdbdf65415f58b59fc5f8ee649aae4 100644 (file)
@@ -1,16 +1,16 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
-@interface MyClass
+@interface MyClass // expected-note {{required for direct or indirect protocol 'P'}}
 @end
 
 @protocol P
 - (void)Pmeth;
-- (void)Pmeth1;
+- (void)Pmeth1; // expected-note {{method definition for 'Pmeth1' not found}}
 @end
 
 // Class extension
 @interface MyClass () <P>
-- (void)meth2;
+- (void)meth2; // expected-note {{method definition for 'meth2' not found}}
 @end
 
 // Add a category to test that clang does not emit warning for this method.
@@ -18,8 +18,6 @@
 - (void)categoryMethod;
 @end
 
-@implementation MyClass // expected-warning {{incomplete implementation}} \
-                           expected-warning {{method definition for 'meth2' not found}} \
-                           expected-warning {{method definition for 'Pmeth1' not found}}
+@implementation MyClass // expected-warning {{incomplete implementation}} 
 - (void)Pmeth {}
 @end
index cfe1d56ee5c86e29f70b2e91a03132af01c755a5..1ebc59e96b3b397dc3597a87c583766807934454 100644 (file)
@@ -3,12 +3,12 @@
 @interface INTF
 - (void) meth;
 - (void) meth : (int) arg1;
-- (int)  int_meth; 
-+ (int) cls_meth;
-+ (void) cls_meth1 : (int) arg1; 
+- (int)  int_meth;  // expected-note {{method definition for 'int_meth' not found}}
++ (int) cls_meth;  // expected-note {{method definition for 'cls_meth' not found}}
++ (void) cls_meth1 : (int) arg1;  // expected-note {{method definition for 'cls_meth1:' not found}}
 @end
 
-@implementation INTF   // expected-warning {{incomplete implementation}} expected-warning {{method definition for 'int_meth' not found}} expected-warning {{method definition for 'cls_meth' not found}} expected-warning {{method definition for 'cls_meth1:' not found}}
+@implementation INTF   // expected-warning {{incomplete implementation}}
 - (void) meth {}
 - (void) meth : (int) arg2{}
 - (void) cls_meth1 : (int) arg2{}
 @interface INTF1
 - (void) meth;
 - (void) meth : (int) arg1;
-- (int)  int_meth;      
-+ (int) cls_meth;       
-+ (void) cls_meth1 : (int) arg1; 
+- (int)  int_meth;       // expected-note {{method definition for 'int_meth' not found}}
++ (int) cls_meth;        // expected-note {{method definition for 'cls_meth' not found}}
++ (void) cls_meth1 : (int) arg1;  // expected-note {{method definition for 'cls_meth1:' not found}}
 @end
 
-@implementation INTF1 // expected-warning {{incomplete implementation}} expected-warning {{method definition for 'int_meth' not found}} expected-warning {{method definition for 'cls_meth' not found}} expected-warning {{method definition for 'cls_meth1:' not found}}
+@implementation INTF1 // expected-warning {{incomplete implementation}}
 - (void) meth {}
 - (void) meth : (int) arg2{}
 - (void) cls_meth1 : (int) arg2{}
index 9a35ef7ba8063ae332397aef34d495c9f79a93de..6871ff06fc514777e9de9b0e5ebd22cc00beeaf6 100644 (file)
@@ -1,40 +1,34 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
 @protocol P1
-- (void) P1proto;
-+ (void) ClsP1Proto;  
+- (void) P1proto; // expected-note {{method definition for 'P1proto' not found}}
++ (void) ClsP1Proto;   // expected-note {{method definition for 'ClsP1Proto' not found}}
 - (void) DefP1proto;
 @end
 @protocol P2
-- (void) P2proto;  
-+ (void) ClsP2Proto; 
+- (void) P2proto;   // expected-note {{method definition for 'P2proto' not found}}
++ (void) ClsP2Proto;  // expected-note {{method definition for 'ClsP2Proto' not found}}
 @end
 
 @protocol P3<P2>
-- (void) P3proto; 
-+ (void) ClsP3Proto; 
+- (void) P3proto;  // expected-note {{method definition for 'P3proto' not found}}
++ (void) ClsP3Proto;  // expected-note {{method definition for 'ClsP3Proto' not found}}
 + (void) DefClsP3Proto;
 @end
 
 @protocol PROTO<P1, P3>
-- (void) meth;         
-- (void) meth : (int) arg1; 
-+ (void) cls_meth : (int) arg1; 
+- (void) meth;          // expected-note {{method definition for 'meth' not found}}
+- (void) meth : (int) arg1;  // expected-note {{method definition for 'meth:' not found}}
++ (void) cls_meth : (int) arg1;  // expected-note {{method definition for 'cls_meth:' not found}}
 @end
 
-@interface INTF <PROTO>
+@interface INTF <PROTO> // expected-note 3 {{required for direct or indirect protocol 'PROTO'}} \
+                       // expected-note 2 {{required for direct or indirect protocol 'P1'}} \
+                       // expected-note 2 {{required for direct or indirect protocol 'P3'}} \
+                       // expected-note 2 {{required for direct or indirect protocol 'P2'}}
 @end
 
-@implementation INTF   // expected-warning {{incomplete implementation}} \
-                          expected-warning {{method definition for 'meth' not found}} \
-                          expected-warning {{method definition for 'meth:' not found}} \
-                          expected-warning {{method definition for 'cls_meth:' not found}} \
-                          expected-warning {{method definition for 'P3proto' not found}} \
-                          expected-warning {{method definition for 'ClsP3Proto' not found}} \
-                          expected-warning {{method definition for 'P2proto' not found}} \
-                          expected-warning {{method definition for 'ClsP2Proto' not found}} \
-                          expected-warning {{method definition for 'ClsP1Proto' not found}} \
-                          expected-warning {{method definition for 'P1proto' not found}}
+@implementation INTF   // expected-warning {{incomplete implementation}} 
 - (void) DefP1proto{}
 
 + (void) DefClsP3Proto{}