Split "incomplete implementation" warnings for ObjC into separate warnings.

Previously all unimplemented methods for a class were grouped under
a single warning, with all the unimplemented methods mentioned
as notes.  Based on feedback from users, most users would like
a separate warning for each method, with a note pointing back to
the original method declaration.

Implements <rdar://problem/13350414>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178097 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ted Kremenek 2013-03-27 00:02:21 +00:00
parent defa32ef4f
commit 8b43d2b0ea
18 changed files with 73 additions and 74 deletions

View File

@ -525,9 +525,8 @@ def err_conflicting_ivar_name : Error<
"conflicting instance variable names: %0 vs %1">;
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">,
InGroup<DiagGroup<"incomplete-implementation">>;
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">;

View File

@ -1177,14 +1177,18 @@ void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
return;
}
if (!IncompleteImpl) {
Diag(ImpLoc, diag::warn_incomplete_impl);
IncompleteImpl = true;
}
if (DiagID == diag::warn_unimplemented_protocol_method)
Diag(ImpLoc, DiagID) << method->getDeclName();
else
Diag(method->getLocation(), DiagID) << method->getDeclName();
// FIXME: For now ignore 'IncompleteImpl'.
// Previously we grouped all unimplemented methods under a single
// warning, but some users strongly voiced that they would prefer
// separate warnings. We will give that approach a try, as that
// matches what we do with protocols.
Diag(ImpLoc, DiagID) << method->getDeclName();
// Issue a note to the original declaration.
SourceLocation MethodLoc = method->getLocStart();
if (MethodLoc.isValid())
Diag(MethodLoc, diag::note_method_declared_at) << method;
}
/// Determines if type B can be substituted for type A. Returns true if we can
@ -1628,8 +1632,6 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc,
if (Diags.getDiagnosticLevel(DIAG, ImpLoc)
!= DiagnosticsEngine::Ignored) {
WarnUndefinedMethod(ImpLoc, method, IncompleteImpl, DIAG);
Diag(method->getLocation(), diag::note_method_declared_at)
<< method->getDeclName();
Diag(CDecl->getLocation(), diag::note_required_for_protocol_at)
<< PDecl->getDeclName();
}
@ -1651,8 +1653,6 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc,
if (Diags.getDiagnosticLevel(DIAG, ImpLoc) !=
DiagnosticsEngine::Ignored) {
WarnUndefinedMethod(ImpLoc, method, IncompleteImpl, DIAG);
Diag(method->getLocation(), diag::note_method_declared_at)
<< method->getDeclName();
Diag(IDecl->getLocation(), diag::note_required_for_protocol_at) <<
PDecl->getDeclName();
}
@ -1687,7 +1687,7 @@ void Sema::MatchAllMethodDeclarations(const SelectorSet &InsMap,
!InsMap.count((*I)->getSelector())) {
if (ImmediateClass)
WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl,
diag::note_undef_method_impl);
diag::warn_undef_method_impl);
continue;
} else {
ObjCMethodDecl *ImpMethodDecl =
@ -1717,7 +1717,7 @@ void Sema::MatchAllMethodDeclarations(const SelectorSet &InsMap,
if (!ClsMap.count((*I)->getSelector())) {
if (ImmediateClass)
WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl,
diag::note_undef_method_impl);
diag::warn_undef_method_impl);
} else {
ObjCMethodDecl *ImpMethodDecl =
IMPDecl->getClassMethod((*I)->getSelector());

View File

@ -1,4 +1,5 @@
// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core -analyzer-store=region -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s
// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core -analyzer-store=region -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 -Wno-incomplete-implementation %s
// expected-no-diagnostics
//===----------------------------------------------------------------------===//
// Delta-debugging produced forward declarations.
@ -32,16 +33,16 @@ typedef struct _NSZone NSZone;
@protocol IHGoogleDocsAdapterDelegate - (void)googleDocsAdapter:(IHGoogleDocsAdapter*)inGoogleDocsAdapter accountVerifyIsValid:(BOOL)inIsValid error:(NSError *)inError;
@end @interface IHGoogleDocsAdapter : NSObject {
}
- (NSArray *)entries; // expected-note {{method definition for 'entries' not found}}
- (NSArray *)entries;
@end extern Class const kGDataUseRegisteredClass ;
@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}}
@interface IHGoogleDocsAdapter () - (GDataFeedDocList *)feedDocList;
- (NSArray *)directoryPathComponents;
- (unsigned int)currentPathComponentIndex;
- (void)setCurrentPathComponentIndex:(unsigned int)aCurrentPathComponentIndex;
- (NSURL *)folderFeedURL;
@end
@implementation IHGoogleDocsAdapter - (id)initWithUsername:(NSString *)inUsername password:(NSString *)inPassword owner:(NSObject <IHGoogleDocsAdapterDelegate> *)owner { // expected-warning {{incomplete implementation}}
@implementation IHGoogleDocsAdapter - (id)initWithUsername:(NSString *)inUsername password:(NSString *)inPassword owner:(NSObject <IHGoogleDocsAdapterDelegate> *)owner {
return 0;
}

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -analyzer-checker=core -verify %s
// RUN: %clang_cc1 -analyzer-checker=core -verify %s -Wno-incomplete-implementation
typedef signed char BOOL;
typedef int NSInteger;
typedef unsigned int NSUInteger;
@ -70,9 +70,9 @@ extern NSMutableArray *XCFindPossibleKeyModules(PBXModule *module, BOOL useExpos
@interface XCPerspectiveModule : PBXProjectModule <PBXSelectionTarget> { // expected-note {{required for direct or indirect protocol 'PBXSelectionTarget'}}
XCExtendedTabView *_perspectivesTabView;
}
- (PBXModule *) moduleForTab:(NSTabViewItem *)item; // expected-note {{method definition for 'moduleForTab:' not found}}
- (PBXModule *) moduleForTab:(NSTabViewItem *)item;
@end
@implementation XCPerspectiveModule // expected-warning {{incomplete implementation}} expected-warning {{method 'performAction:withSelection:' in protocol not implemented}}}
@implementation XCPerspectiveModule // expected-warning {{method 'performAction:withSelection:' in protocol not implemented}}}
+ (void) openForProjectDocument:(PBXProjectDocument *)projectDocument {
}
- (PBXModule *) type:(Class)type inPerspective:(id)perspectiveIdentifer matchingFunction:(BOOL (void *, void *))comparator usingData:(void *)data {

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-checker=core,alpha.core -analyzer-store=region -verify %s
// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-checker=core,alpha.core -analyzer-store=region -Wno-incomplete-implementation -verify %s
// This test case was crashing due to how CFRefCount.cpp resolved the
// ObjCInterfaceDecl* and ClassName in EvalObjCMessageExpr.
@ -47,14 +47,14 @@ CMProfileLocation;
@interface GBCategoryChooserPanelController : NSWindowController {
GSEbayCategory *rootCategory;
}
- (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}} expected-note {{using}}
- (NSMutableDictionary*)categoryDictionaryForCategoryID:(int)inID inRootTreeCategories:(NSMutableArray*)inRootTreeCategories;
-(NSString*) categoryID; // expected-note {{using}}
@end @interface GSEbayCategory : NSObject <NSCoding> {
}
- (int) categoryID; // expected-note {{also found}}
- (GSEbayCategory *) parent;
- (GSEbayCategory*) subcategoryWithID:(int) inID;
@end @implementation GBCategoryChooserPanelController + (int) chooseCategoryIDFromCategories:(NSArray*) inCategories searchRequest:(GBSearchRequest*)inRequest parentWindow:(NSWindow*) inParent { // expected-warning {{incomplete implementation}}
@end @implementation GBCategoryChooserPanelController + (int) chooseCategoryIDFromCategories:(NSArray*) inCategories searchRequest:(GBSearchRequest*)inRequest parentWindow:(NSWindow*) inParent {
return 0;
}
- (void) addCategory:(EBayCategoryType*)inCategory toRootTreeCategory:(NSMutableArray*)inRootTreeCategories {

View File

@ -71,8 +71,7 @@
@interface MultipleCat_I() <MultipleCat_P> @end
@implementation MultipleCat_I // expected-warning {{incomplete implementation}} \
// expected-warning {{method 'im0' in protocol not implemented}}
@implementation MultipleCat_I // expected-warning {{method 'im0' in protocol not implemented}}
@end
// <rdar://problem/7680391> - Handle nameless categories with no name that refer

View File

@ -23,8 +23,7 @@ extern NSString * const NSTaskDidTerminateNotification;
- (NSString *)evaluateAsStringInContext:(XCPropertyExpansionContext *)context withNestingState:(const void *)state;
@end
@implementation XCPropertyExpansionContext // expected-warning {{incomplete implementation}} \
// expected-warning {{method 'copyWithZone:' in protocol not implemented}}
@implementation XCPropertyExpansionContext // expected-warning {{method 'copyWithZone:' in protocol not implemented}}
- (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)) { }

View File

@ -21,10 +21,10 @@
@end
@interface DTFilterOutputStream2
- nextOutputStream; // expected-note {{method definition for 'nextOutputStream' not found}}
- nextOutputStream; // expected-note {{method 'nextOutputStream' declared here}}
@end
@implementation DTFilterOutputStream2 // expected-warning {{incomplete implementation}}
@implementation DTFilterOutputStream2 // expected-warning {{method definition for 'nextOutputStream' not found}}
- (id)initWithNextOutputStream:(id <DTOutputStreams>) outputStream {
id <DTOutputStreams> nextOutputStream = [self nextOutputStream];
self = nextOutputStream; // expected-warning {{assigning to 'DTFilterOutputStream2 *' from incompatible type 'id<DTOutputStreams>'}}

View File

@ -16,6 +16,5 @@
@end
@implementation IBImageCatalogDocument // expected-warning {{auto property synthesis will not synthesize property declared in a protocol}} \
// expected-warning {{incomplete implementation}} \
// expected-warning {{method 'invalidate' in protocol not implemented}}
@end

View File

@ -5,8 +5,8 @@ typedef struct _NSRange { } NSRange;
@class PBXFileReference;
@interface PBXDocBookmark
+ alloc; // expected-note {{method definition for 'alloc' not found}}
- autorelease; // expected-note {{method definition for 'autorelease' not found}}
+ alloc; // expected-note {{method 'alloc' declared here}}
- autorelease; // expected-note {{method 'autorelease' declared here}}
@end
// GCC allows pointer expressions in integer constant expressions.
@ -14,7 +14,8 @@ struct {
char control[((int)(char *)2)];
} xx;
@implementation PBXDocBookmark // expected-warning {{incomplete implementation}}
@implementation PBXDocBookmark // expected-warning {{method definition for 'autorelease' not found}}\
// expected-warning {{method definition for 'alloc' not found}}
+ (id)bookmarkWithFileReference:(PBXFileReference *)fileRef gylphRange:(NSRange)range anchor:(NSString *)htmlAnchor
{

View File

@ -1,13 +1,12 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify -Wno-objc-root-class %s
@interface I
- Meth; // expected-note{{method definition for 'Meth' not found}} \
// expected-note{{method 'Meth' declared here}}
- Meth; // expected-note 2 {{method 'Meth' declared here}}
- unavailableMeth __attribute__((availability(macosx,unavailable)));
- unavailableMeth2 __attribute__((unavailable));
@end
@implementation I // expected-warning{{incomplete implementation}}
@implementation I // expected-warning {{method definition for 'Meth' not found}}
@end
@implementation I(CAT)

View File

@ -4,25 +4,25 @@
@end
@protocol P
- (void) Pmeth; // expected-note {{method 'Pmeth' declared here}}
- (void) Pmeth1; // expected-note {{method 'Pmeth1' declared here}}
- (void) Pmeth; // expected-note {{method 'Pmeth' declared here}}
- (void) Pmeth1; // expected-note {{method 'Pmeth1' declared here}}
@end
@interface MyClass1(CAT) <P> // expected-note {{required for direct or indirect protocol 'P'}}
- (void) meth2; // expected-note {{method definition for 'meth2' not found}}
- (void) meth2; // expected-note {{method 'meth2' declared here}}
@end
@implementation MyClass1(CAT) // expected-warning {{incomplete implementation}} \
// expected-warning {{method 'Pmeth' in protocol not implemented}}
@implementation MyClass1(CAT) // expected-warning {{method 'Pmeth' in protocol not implemented}} \
// expected-warning {{method definition for 'meth2' not found}}
- (void) Pmeth1{}
@end
@interface MyClass1(DOG) <P> // expected-note {{required for direct or indirect protocol 'P'}}
- (void)ppp; // expected-note {{method definition for 'ppp' not found}}
- (void)ppp; // expected-note {{method 'ppp' declared here}}
@end
@implementation MyClass1(DOG) // expected-warning {{incomplete implementation}} \
// expected-warning {{method 'Pmeth1' in protocol not implemented}}
@implementation MyClass1(DOG) // expected-warning {{method 'Pmeth1' in protocol not implemented}} \
// expected-warning {{method definition for 'ppp' not found}}
- (void) Pmeth {}
@end

View File

@ -10,7 +10,7 @@
// Class extension
@interface MyClass () <P>
- (void)meth2; // expected-note {{method definition for 'meth2' not found}}
- (void)meth2; // expected-note {{method 'meth2' declared here}}
@end
// Add a category to test that clang does not emit warning for this method.
@ -18,7 +18,7 @@
- (void)categoryMethod;
@end
@implementation MyClass // expected-warning {{incomplete implementation}} \
// expected-warning {{method 'Pmeth1' in protocol not implemented}}
@implementation MyClass // expected-warning {{method 'Pmeth1' in protocol not implemented}} \
// expected-warning {{method definition for 'meth2' not found}}
- (void)Pmeth {}
@end

View File

@ -3,12 +3,14 @@
@interface INTF
- (void) meth;
- (void) meth : (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}}
- (int) int_meth; // expected-note {{method 'int_meth' declared here}}
+ (int) cls_meth; // expected-note {{method 'cls_meth' declared here}}
+ (void) cls_meth1 : (int) arg1; // expected-note {{method 'cls_meth1:' declared here}}
@end
@implementation INTF // expected-warning {{incomplete implementation}}
@implementation INTF // 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}}
- (void) meth {}
- (void) meth : (int) arg2{}
- (void) cls_meth1 : (int) arg2{}
@ -17,12 +19,14 @@
@interface INTF1
- (void) meth;
- (void) meth : (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}}
- (int) int_meth; // expected-note {{method 'int_meth' declared here}}
+ (int) cls_meth; // expected-note {{method 'cls_meth' declared here}}
+ (void) cls_meth1 : (int) arg1; // expected-note {{method 'cls_meth1:' declared here}}
@end
@implementation INTF1 // expected-warning {{incomplete implementation}}
@implementation INTF1 // 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}}
- (void) meth {}
- (void) meth : (int) arg2{}
- (void) cls_meth1 : (int) arg2{}

View File

@ -17,9 +17,9 @@
// Test2
@interface super - PMeth; @end
@interface J : super <P>
- PMeth; // expected-note {{method definition for 'PMeth' not found}}
- PMeth; // expected-note {{method 'PMeth' declared here}}
@end
@implementation J @end // expected-warning {{incomplete implementation}}
@implementation J @end // expected-warning {{method definition for 'PMeth' not found}}
// Test3
@interface K : super <P>

View File

@ -37,11 +37,12 @@ void FUNC () {
@interface rdar8747333 ()
- (NSObject *)bam;
- (NSObject *)warn; // expected-note {{method definition for 'warn' not found}}
- (void)setWarn : (NSObject *)val; // expected-note {{method definition for 'setWarn:' not found}}
- (NSObject *)warn; // expected-note {{method 'warn' declared here}}
- (void)setWarn : (NSObject *)val; // expected-note {{method 'setWarn:' declared here}}
@end
@implementation rdar8747333 // expected-warning {{incomplete implementation}}
@implementation rdar8747333 // expected-warning {{method definition for 'warn' not found}} \
// expected-warning {{method definition for 'setWarn:' not found}}
@synthesize bar = _bar;
@synthesize baz = _baz;
@synthesize bam = _bam;

View File

@ -28,10 +28,7 @@
// expected-note 2 {{required for direct or indirect protocol 'P2'}}
@end
@implementation INTF // expected-warning {{incomplete implementation}} \
// expected-warning 9 {{in protocol not implemented}}
@implementation INTF // expected-warning 9 {{in protocol not implemented}}
- (void) DefP1proto{}
+ (void) DefClsP3Proto{}
@end

View File

@ -15,11 +15,11 @@
- method:(id) second:(id)second; // expected-warning {{'second' used as the name of the previous parameter rather than as part of the selector}} \
// expected-note {{introduce a parameter name to make 'second' part of the selector}} \
// expected-note {{or insert whitespace before ':' to use 'second' as parameter name and have an empty entry in the selector}} \
// expected-note {{method definition for 'method::' not found}}
// expected-note {{method 'method::' declared here}}
@end
@implementation INTF // expected-warning {{incomplete implementation}}
@implementation INTF // expected-warning {{method definition for 'method::' not found}}
-(void) Name1:(id)Arg1 Name2:(id)Arg2{}
-(void) Name1:(id) Name2:(id)Arg2 {} // expected-warning {{'Name2' used as the name of the previous parameter rather than as part of the selector}} \
// expected-note {{introduce a parameter name to make 'Name2' part of the selector}} \