From 2ccf19e1ab7496ab9a3ae11e93669281beea81e8 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 13 Dec 2013 05:58:51 +0000 Subject: [PATCH] Change 'method X in protocol not implemented' warning to include the name of the protocol. This removes an extra "note:", which wasn't really all that more useful and overall reduces the diagnostic spew for this case. llvm-svn: 197207 --- .../clang/Basic/DiagnosticSemaKinds.td | 2 +- clang/lib/Sema/SemaDeclObjC.cpp | 19 +++++++++++-------- clang/test/Analysis/method-arg-decay.m | 4 ++-- clang/test/SemaObjC/category-1.m | 4 ++-- clang/test/SemaObjC/compare-qualified-id.m | 4 ++-- .../forward-protocol-incomplete-impl-warn.m | 4 ++-- .../SemaObjC/method-undef-category-warn-1.m | 8 ++++---- .../SemaObjC/method-undef-extension-warn-1.m | 4 ++-- .../SemaObjC/protocols-suppress-conformance.m | 8 ++++---- .../test/SemaObjC/undef-protocol-methods-1.m | 7 ++----- 10 files changed, 32 insertions(+), 32 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index b0deed75ec53..9f1766311900 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -852,7 +852,7 @@ def warn_unimplemented_selector: Warning< def warning_multiple_selectors: Warning< "multiple selectors named %0 found">, InGroup, DefaultIgnore; def warn_unimplemented_protocol_method : Warning< - "method %0 in protocol not implemented">, InGroup; + "method %0 in protocol %1 not implemented">, InGroup; // C++ declarations def err_static_assert_expression_is_not_constant : Error< diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 0ecd98089f66..723fbdb6e675 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -1228,7 +1228,8 @@ void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, static void WarnUndefinedMethod(Sema &S, SourceLocation ImpLoc, ObjCMethodDecl *method, bool &IncompleteImpl, - unsigned DiagID) { + unsigned DiagID, + NamedDecl *NeededFor = 0) { // No point warning no definition of method which is 'unavailable'. switch (method->getAvailability()) { case AR_Available: @@ -1246,7 +1247,12 @@ static void WarnUndefinedMethod(Sema &S, SourceLocation ImpLoc, // 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. - S.Diag(ImpLoc, DiagID) << method->getDeclName(); + { + const Sema::SemaDiagnosticBuilder &B = S.Diag(ImpLoc, DiagID); + B << method; + if (NeededFor) + B << NeededFor; + } // Issue a note to the original declaration. SourceLocation MethodLoc = method->getLocStart(); @@ -1702,9 +1708,8 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc, unsigned DIAG = diag::warn_unimplemented_protocol_method; if (Diags.getDiagnosticLevel(DIAG, ImpLoc) != DiagnosticsEngine::Ignored) { - WarnUndefinedMethod(*this, ImpLoc, method, IncompleteImpl, DIAG); - Diag(CDecl->getLocation(), diag::note_required_for_protocol_at) - << PDecl->getDeclName(); + WarnUndefinedMethod(*this, ImpLoc, method, IncompleteImpl, DIAG, + PDecl); } } } @@ -1730,9 +1735,7 @@ void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc, unsigned DIAG = diag::warn_unimplemented_protocol_method; if (Diags.getDiagnosticLevel(DIAG, ImpLoc) != DiagnosticsEngine::Ignored) { - WarnUndefinedMethod(*this, ImpLoc, method, IncompleteImpl, DIAG); - Diag(IDecl->getLocation(), diag::note_required_for_protocol_at) << - PDecl->getDeclName(); + WarnUndefinedMethod(*this, ImpLoc, method, IncompleteImpl, DIAG, PDecl); } } } diff --git a/clang/test/Analysis/method-arg-decay.m b/clang/test/Analysis/method-arg-decay.m index 0af9e3e883e3..a222346861a5 100644 --- a/clang/test/Analysis/method-arg-decay.m +++ b/clang/test/Analysis/method-arg-decay.m @@ -67,12 +67,12 @@ extern NSMutableArray *XCFindPossibleKeyModules(PBXModule *module, BOOL useExpos @interface XCExtendedTabView : NSTabView { } @end @class PBXProjectDocument, PBXFileReference, PBXModule, XCWindowTool; -@interface XCPerspectiveModule : PBXProjectModule { // expected-note {{required for direct or indirect protocol 'PBXSelectionTarget'}} +@interface XCPerspectiveModule : PBXProjectModule { XCExtendedTabView *_perspectivesTabView; } - (PBXModule *) moduleForTab:(NSTabViewItem *)item; @end -@implementation XCPerspectiveModule // expected-warning {{method 'performAction:withSelection:' in protocol not implemented}}} +@implementation XCPerspectiveModule // expected-warning {{method 'performAction:withSelection:' in protocol 'PBXSelectionTarget' not implemented}}} + (void) openForProjectDocument:(PBXProjectDocument *)projectDocument { } - (PBXModule *) type:(Class)type inPerspective:(id)perspectiveIdentifer matchingFunction:(BOOL (void *, void *))comparator usingData:(void *)data { diff --git a/clang/test/SemaObjC/category-1.m b/clang/test/SemaObjC/category-1.m index 18b872aa8b8a..3c2f7d0032a0 100644 --- a/clang/test/SemaObjC/category-1.m +++ b/clang/test/SemaObjC/category-1.m @@ -65,13 +65,13 @@ -(void) im0; // expected-note {{method 'im0' declared here}} @end -@interface MultipleCat_I @end // expected-note {{required for direct or indirect protocol 'MultipleCat_P'}} +@interface MultipleCat_I @end @interface MultipleCat_I() @end @interface MultipleCat_I() @end -@implementation MultipleCat_I // expected-warning {{method 'im0' in protocol not implemented}} +@implementation MultipleCat_I // expected-warning {{method 'im0' in protocol 'MultipleCat_P' not implemented}} @end // - Handle nameless categories with no name that refer diff --git a/clang/test/SemaObjC/compare-qualified-id.m b/clang/test/SemaObjC/compare-qualified-id.m index 02fa86ec8d9e..7da774957e58 100644 --- a/clang/test/SemaObjC/compare-qualified-id.m +++ b/clang/test/SemaObjC/compare-qualified-id.m @@ -15,7 +15,7 @@ typedef struct {} NSFastEnumerationState; @interface NSMutableDictionary : NSDictionary - (void)removeObjectForKey:(id)aKey; @end // expected-note {{receiver is instance of class declared here}} extern NSString * const NSTaskDidTerminateNotification; -@interface XCPropertyExpansionContext : NSObject { // expected-note {{required for direct or indirect protocol 'NSCopying'}} +@interface XCPropertyExpansionContext : NSObject { NSMutableDictionary * _propNamesToPropValuesCache; } @end @@ -23,7 +23,7 @@ extern NSString * const NSTaskDidTerminateNotification; - (NSString *)evaluateAsStringInContext:(XCPropertyExpansionContext *)context withNestingState:(const void *)state; @end -@implementation XCPropertyExpansionContext // expected-warning {{method 'copyWithZone:' in protocol not implemented}} +@implementation XCPropertyExpansionContext // expected-warning {{method 'copyWithZone:' in protocol 'NSCopying' not implemented}} - (NSString *)expandedValueForProperty:(NSString *)property { id cachedValueNode = [_propNamesToPropValuesCache objectForKey:property]; // expected-warning {{method '-objectForKey:' not found (return type defaults to 'id')}} if (cachedValueNode == ((void *)0)) { } diff --git a/clang/test/SemaObjC/forward-protocol-incomplete-impl-warn.m b/clang/test/SemaObjC/forward-protocol-incomplete-impl-warn.m index 654ef59f3d82..94a516adf9b2 100644 --- a/clang/test/SemaObjC/forward-protocol-incomplete-impl-warn.m +++ b/clang/test/SemaObjC/forward-protocol-incomplete-impl-warn.m @@ -12,9 +12,9 @@ @protocol DVTInvalidation; -@interface IBImageCatalogDocument : NSObject // expected-note {{required for direct or indirect protocol 'DVTInvalidation'}} +@interface IBImageCatalogDocument : NSObject @end @implementation IBImageCatalogDocument // expected-warning {{auto property synthesis will not synthesize property 'Prop' declared in protocol 'DVTInvalidation'}} \ - // expected-warning {{method 'invalidate' in protocol not implemented}} + // expected-warning {{method 'invalidate' in protocol 'DVTInvalidation' not implemented}} @end diff --git a/clang/test/SemaObjC/method-undef-category-warn-1.m b/clang/test/SemaObjC/method-undef-category-warn-1.m index 98d732babb93..c951db2ca1a3 100644 --- a/clang/test/SemaObjC/method-undef-category-warn-1.m +++ b/clang/test/SemaObjC/method-undef-category-warn-1.m @@ -8,20 +8,20 @@ - (void) Pmeth1; // expected-note {{method 'Pmeth1' declared here}} @end -@interface MyClass1(CAT)

// expected-note {{required for direct or indirect protocol 'P'}} +@interface MyClass1(CAT)

- (void) meth2; // expected-note {{method 'meth2' declared here}} @end -@implementation MyClass1(CAT) // expected-warning {{method 'Pmeth' in protocol not implemented}} \ +@implementation MyClass1(CAT) // expected-warning {{method 'Pmeth' in protocol 'P' not implemented}} \ // expected-warning {{method definition for 'meth2' not found}} - (void) Pmeth1{} @end -@interface MyClass1(DOG)

// expected-note {{required for direct or indirect protocol 'P'}} +@interface MyClass1(DOG)

- (void)ppp; // expected-note {{method 'ppp' declared here}} @end -@implementation MyClass1(DOG) // expected-warning {{method 'Pmeth1' in protocol not implemented}} \ +@implementation MyClass1(DOG) // expected-warning {{method 'Pmeth1' in protocol 'P' not implemented}} \ // expected-warning {{method definition for 'ppp' not found}} - (void) Pmeth {} @end diff --git a/clang/test/SemaObjC/method-undef-extension-warn-1.m b/clang/test/SemaObjC/method-undef-extension-warn-1.m index fbc21bd39f6a..819d6ed86ff3 100644 --- a/clang/test/SemaObjC/method-undef-extension-warn-1.m +++ b/clang/test/SemaObjC/method-undef-extension-warn-1.m @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s -@interface MyClass // expected-note {{required for direct or indirect protocol 'P'}} +@interface MyClass @end @protocol P @@ -18,7 +18,7 @@ - (void)categoryMethod; @end -@implementation MyClass // expected-warning {{method 'Pmeth1' in protocol not implemented}} \ +@implementation MyClass // expected-warning {{method 'Pmeth1' in protocol 'P' not implemented}} \ // expected-warning {{method definition for 'meth2' not found}} - (void)Pmeth {} @end diff --git a/clang/test/SemaObjC/protocols-suppress-conformance.m b/clang/test/SemaObjC/protocols-suppress-conformance.m index 3349f7f90a43..f62b28517558 100644 --- a/clang/test/SemaObjC/protocols-suppress-conformance.m +++ b/clang/test/SemaObjC/protocols-suppress-conformance.m @@ -18,10 +18,10 @@ __attribute__((objc_protocol_requires_explicit_implementation)) // This class subclasses ClassA (which adopts 'Protocol'), // but does not provide the needed implementation. -@interface ClassB : ClassA // expected-note {{required for direct or indirect protocol 'Protocol'}} +@interface ClassB : ClassA @end -@implementation ClassB // expected-warning {{method 'theBestOfTimes' in protocol not implemented}} +@implementation ClassB // expected-warning {{method 'theBestOfTimes' in protocol 'Protocol' not implemented}} @end // Test that inherited protocols do not get the explicit conformance requirement. @@ -37,10 +37,10 @@ __attribute__((objc_protocol_requires_explicit_implementation)) @interface ClassC @end -@interface ClassD : ClassC // expected-note {{required for direct or indirect protocol 'Derived'}} +@interface ClassD : ClassC @end -@implementation ClassD // expected-warning {{method 'foulIsFair' in protocol not implemented}} +@implementation ClassD // expected-warning {{method 'foulIsFair' in protocol 'Derived' not implemented}} @end // Test that the attribute is used correctly. diff --git a/clang/test/SemaObjC/undef-protocol-methods-1.m b/clang/test/SemaObjC/undef-protocol-methods-1.m index 25b1dadb7cce..4858faf28031 100644 --- a/clang/test/SemaObjC/undef-protocol-methods-1.m +++ b/clang/test/SemaObjC/undef-protocol-methods-1.m @@ -22,13 +22,10 @@ + (void) cls_meth : (int) arg1; // expected-note {{method 'cls_meth:' declared here}} @end -@interface INTF // 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'}} +@interface INTF @end -@implementation INTF // expected-warning 9 {{in protocol not implemented}} +@implementation INTF // expected-warning 9 {{in protocol '}} - (void) DefP1proto{} + (void) DefClsP3Proto{} @end