This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] performance-for-range-copy: Don't trigger on implicit type conversions.
ClosedPublic

Authored by flx on Feb 26 2021, 1:36 PM.

Details

Summary

This disables the check for false positive cases where implicit type conversion
through either an implicit single argument constructor or a member conversion
operator is triggered when constructing the loop variable.

Fix the test cases that meant to cover these cases.

Diff Detail

Event Timeline

flx created this revision.Feb 26 2021, 1:36 PM
flx requested review of this revision.Feb 26 2021, 1:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 26 2021, 1:36 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
flx updated this revision to Diff 326792.Feb 26 2021, 1:37 PM

Remove include.

flx updated this revision to Diff 326793.Feb 26 2021, 1:38 PM

Remove include.

Eugene.Zelenko added a project: Restricted Project.

It is best not to change existing tests, but add new ones.

flx added a comment.Feb 28 2021, 8:10 AM

It is best not to change existing tests, but add new ones.

Could elaborate on this, Roman?

In this case the tests use special auto convertible types with the intention to test that the check doesn't trigger because the loop variable needs to be constructed. But the reason they don't trigger is that the loop variable erroneously is already a reference type.

If we keep the tests as is we should rename the test functions and use different types or document that the real reason they don't trigger is that they already are const reference types, but we already have a test for that as well.

hokein accepted this revision.Mar 1 2021, 11:15 PM
In D97577#2592827, @flx wrote:

It is best not to change existing tests, but add new ones.

Could elaborate on this, Roman?

In this case the tests use special auto convertible types with the intention to test that the check doesn't trigger because the loop variable needs to be constructed. But the reason they don't trigger is that the loop variable erroneously is already a reference type.

If we keep the tests as is we should rename the test functions and use different types or document that the real reason they don't trigger is that they already are const reference types, but we already have a test for that as well.

The explanation sounds plausible, thanks.

This revision is now accepted and ready to land.Mar 1 2021, 11:15 PM
In D97577#2592827, @flx wrote:

It is best not to change existing tests, but add new ones.

Could elaborate on this, Roman?

In this case the tests use special auto convertible types with the intention to test that the check doesn't trigger because the loop variable needs to be constructed. But the reason they don't trigger is that the loop variable erroneously is already a reference type.

If we keep the tests as is we should rename the test functions and use different types or document that the real reason they don't trigger is that they already are const reference types, but we already have a test for that as well.

The explanation sounds plausible, thanks.

Yep, no further comments from me.

flx added a comment.Mar 2 2021, 5:01 PM

Thank you for the review!