[PATCH] D61147: [Sema][ObjC] Add a flavor of -Wunused-parameter that doesn't diagnose unused parameters of ObjC methods

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 25 22:57:11 PDT 2019

rjmccall added a comment.

In D61147#1479940 <https://reviews.llvm.org/D61147#1479940>, @erik.pilkington wrote:

> In D61147#1479932 <https://reviews.llvm.org/D61147#1479932>, @rjmccall wrote:
> > I do not think the ObjC version of this diagnostic is useful as it's been explained here, and I would strongly recommend just not including such a warning for the time being.
> Why? It seems to me like the vast majority of methods only declared in an `@implementation` are used as local helpers (even if people probably should be using functions for this), where this warning would be useful. Maybe I'm missing something? Still trying to learn more about Objective-C.

What rule are you suggesting for whether a method is "only declared in an `@implementation`"?  Where exactly are you proposing to look for other declarations?

Objective-C does not have a formalized notion of an `@implementation`-private method, or really even an unambiguous convention for them (underscoring is *library*-private by convention, not class-private).  The Objective-C ecosystem includes a lot of informal protocols and conventions based around discovery via naming, and Objective-C programmers do (admittedly rarely) just override methods that they know are there but which they can't see.  These things make me very worried about trying to port assumptions from other languages.

Anyway, put that aside for a minute.  As I understand it, your current proposal is to make `-Wunused-parameter` not fire on the majority of Objective-C methods and then add a new `-Wunused-objc-parameter` warning that's not really formally related to `-Wunused-parameter`.  I think the right way to think about that is that the new warning is an independent feature which can happen at its own pace.  You will need to do some investigation in order to implement that feature, so in the short term, you should just not warn about unused parameters in Objective-C methods, and then you can do the investigation for generalizing the warning as time permits.

  rC Clang



More information about the cfe-commits mailing list