As a heuristic, only warn if the selector matches a method declared in the current interface.
rdar://64621668
Paths
| Differential D82611
[SemaObjC] Add a warning for @selector expressions that potentially refer to objc_direct methods ClosedPublic Authored by erik.pilkington on Jun 25 2020, 4:39 PM.
Details Summary As a heuristic, only warn if the selector matches a method declared in the current interface. rdar://64621668
Diff Detail
Event TimelineHerald added subscribers: ributzka, dexonsmith, jkorous. · View Herald TranscriptJun 25 2020, 4:39 PM Comment Actions So the risk with that one is that if someone had say the -didSomething direct selector and that some UIKit/Apple SDK API now adds this as a thing that you use with CFNotification center for example, where you _need_ dynamism, then the uses of the API would warn all the time when the internal to the client project -didSomething is in scope. So we ideally need a way to silence this warning, so at the very least this needs to be a new -W flag (on by default (?)) so that callers that have an issue can use a _Pragma at the call site to ignore the error for when it's legal. I would suggest something like -Wstrict-direct-dispatch or something.
erik.pilkington marked 3 inline comments as done. Comment ActionsAdd an off-by-default variant of this warning. Comment Actions
The DiagGroup<"potentially-direct-selector"> creates a command line flag, so the pragma thing works. I couldn't think of a decent way of suppressing this without pragmas, but ISTM that this will have a low enough false-positive rate that it won't be a big problem.
I kinda prefer -Wpotentially-direct-selector, since that seems to more closely correspond to what the compiler is complaining about. WDYT?
Comment Actions
Yes, that is better, I wasn't dead-set on the name. This revision is now accepted and ready to land.Jul 6 2020, 6:04 PM Closed by commit rG7437a9496528: [SemaObjC] Add a warning for @selector expressions that potentially refer to… (authored by erik.pilkington). · Explain WhyJul 7 2020, 10:30 AM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 276129 clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExprObjC.cpp
clang/test/SemaObjC/potentially-direct-selector.m
|
missing line between the functions?