This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Don't offer partial fix-its for `modernize-pass-by-value`
ClosedPublic

Authored by avogelsgesang on Oct 27 2021, 11:58 AM.

Details

Summary

This commit improves the fix-its of modernize-pass-by-value by
no longer proposing partial fixes. In the presence of using/typedef,
we failed to rewrite the function signature but still adjusted the
function body. This led to incorrect, partial fix-its. Instead, the
check now simply doesn't offer any fixes at all in such a situation

Diff Detail

Event Timeline

avogelsgesang created this revision.Oct 27 2021, 11:58 AM
avogelsgesang requested review of this revision.Oct 27 2021, 11:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 27 2021, 11:58 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
avogelsgesang added a subscriber: alexfh.

not sure whom to add as a reviewer. According to git log this check wasn't changed for a while...
Adding @alexfh based on CODE_OWNERS.TXT

@ymandel, @whisperity, @aaron.ballman could one of you review this/point me in the direction of a good reviewer for this change?
(Sorry for the spam - I am new to the LLVM project, and I guess I still have to learn how to navigate Phabricator/find the correct reviewers for my changes)

@ymandel, @whisperity, @aaron.ballman could one of you review this/point me in the direction of a good reviewer for this change?
(Sorry for the spam - I am new to the LLVM project, and I guess I still have to learn how to navigate Phabricator/find the correct reviewers for my changes)

No worries; this is not spam, it was super handy for raising awareness!

I've added a few more reviewers who can hopefully help. I'll try to take a look once I get the chance, but I'm pretty swamped currently with C standards meetings this week. Also, the LLVM dev conference is this week, so reviewers may be hard to come by. Thank you for your patience though!

Thanks for your patience!

clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
198

Please spell out this type (per our usual coding conventions). The use on the next line is fine because the type name is spelled out in the initialization.

211–221

I don't think we should take these changes, unless they're strictly necessary for program correctness. The rule of thumb in clang-tidy for fix-its is that we do not make much attempt to have pretty formatting from the fix (the fix needs to be correct, but doesn't need to be formatted); the user can run clang-format after applying fixes. Someday, we'd like to consume clang-format as a library and automatically reformat the code after applying fixes instead of trying to catch every formatting concern in each individual check.

212–216

Please spell out the types.

218–220

(Style guideline nit)

avogelsgesang marked 4 inline comments as done.

Address review comments

clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
198

Thanks for the hint. I wasn't aware of that convention. I fixed it here.

Should I also fix the other violations in this file?

E.g., a couple of lines above, we have

auto Diag = diag(ParamDecl->getBeginLoc(), "pass by value and use std::move");

which I guess should be

clang::DiagnosticBuilder Diag = diag(ParamDecl->getBeginLoc(), "pass by value and use std::move");
211–221

sounds good. Removed the whitespace related parts from this patch

212–216

no longer applicable after removing the whitespace related part of this patch

218–220

no longer applicable after removing the whitespace related part of this patch

avogelsgesang retitled this revision from [clang-tidy] Improve fix-its for `modernize-pass-by-value` check to [clang-tidy] Don't offer partial fix-its for `modernize-pass-by-value`.Dec 1 2021, 11:17 AM
avogelsgesang edited the summary of this revision. (Show Details)
aaron.ballman accepted this revision.Dec 1 2021, 11:57 AM

LGTM aside from a small commenting nit.

clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
194
198

Thanks for the hint. I wasn't aware of that convention.

No problem! In case you haven't seen it, we document our coding style here: https://llvm.org/docs/CodingStandards.html

Should I also fix the other violations in this file?

If you want to, you can do it as an NFC change separate from these changes, but I certainly don't insist.

This revision is now accepted and ready to land.Dec 1 2021, 11:57 AM
avogelsgesang marked an inline comment as done.

Add missing dot to comment

@aaron.ballman can you please commit this on my behalf? I don't have commit access

@aaron.ballman can you please commit this on my behalf? I don't have commit access

OMG, I'm sorry for missing this note! Yes, I'm happy to commit on your behalf. What name and email address would you like me to use for patch attribution?

What name and email address would you like me to use for patch attribution?

Adrian Vogelsgesang, avogelsgesang@salesforce.com

aaron.ballman closed this revision.Dec 8 2021, 10:32 AM

Thanks for the fix and your patience with getting it landed! I've commit on your behalf in 5d3b8956e83484ff7234dda5e939abbdc9bd2c88