This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Limit non-Strict mode to public functions
AbandonedPublic

Authored by mehdi_amini on Jan 2 2022, 6:25 PM.

Details

Reviewers
aaron.ballman
Summary

The rational to avoid applying the warning/fix in non-Strict more to
functions with an empty body is that there is "no place for a bug to hide".
However for private functions, the parameters can be entirely eliminated
and all the call sites improved.

Diff Detail

Event Timeline

mehdi_amini created this revision.Jan 2 2022, 6:25 PM
mehdi_amini requested review of this revision.Jan 2 2022, 6:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 2 2022, 6:25 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman requested changes to this revision.Jan 5 2022, 6:44 AM
aaron.ballman added inline comments.
clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
188

This is looking at the linkage of the function, not at its access control; is that intended?

clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst
43

Call sites are not always visible for protected functions, so this seems a bit suspicious. The changes are missing test coverage for that situation.

clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
157–159

I think this demonstrates a bad fix -- this changes code meaning from being a converting constructor to being a default constructor, which are very different things.

This revision now requires changes to proceed.Jan 5 2022, 6:44 AM
mehdi_amini added inline comments.Jan 5 2022, 6:19 PM
clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst
43

You're using public for "access control" while I was using the linkage aspect: my reasoning is that if a method isn't "externally visible" from the current translation unit, you see all the call-sites. This is orthogonal to public/private/protected as far as I know.

I am likely missing a check for "isDefinedInMainFile" (or whatever the api is called) to not flag included headers.

clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
157–159

Oh you're right: so we can't do it for a Ctor with a single parameter...

But we also can't do it for a Ctor with two parameters as it'll turn it into a converting ctor. Unless you can eliminate both parameters, in which case it is become a default ctor (which can conflict with an existing one, in which case it can be just deleted?)

aaron.ballman added inline comments.Jan 6 2022, 6:30 AM
clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst
43

You're using public for "access control" while I was using the linkage aspect: my reasoning is that if a method isn't "externally visible" from the current translation unit, you see all the call-sites.

Oh, thanks for pointing out that I was confused! I'm not used to "public" when describing linkage, usually that's "external" or "externally visible". Any appetite for rewording in those terms? Something like "On the other hand, for functions with internal linkage, all the call sites are visible and parameters can be safely removed."

clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
157–159

Yeah, I think we need to not transform ctors at all currently.

mehdi_amini abandoned this revision.Jan 7 2022, 12:50 PM
mehdi_amini added inline comments.
clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst
43

Sure: happy to reword.

(We use public/private for symbol visibility at a module level in MLIR unfortunately, I've been "contaminated" ;) ).

clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp
157–159

In this case I can fix the existing bug by disabling the fixit (as discussed in D116513) and abandon this revision I think.