This is an archive of the discontinued LLVM Phabricator instance.

Another patch for modernize-loop-convert.
ClosedPublic

Authored by angelgarcia on Sep 9 2015, 9:04 AM.

Details

Summary
  1. Avoid converting loops that iterate over the size of a container and don't use its elements, as this would result in an unused-result warning.
  2. Never capture the elements by value on lambdas, thus avoiding doing unnecessary copies and errors with non-copyable types.
  3. The 'const auto &' instead of 'auto &' substitution on const containers now works on arrays and pseudoarrays as well.
  4. The error about multiple replacements in the same macro call is now documented in the tests (not solved though).
  5. Due to [1], I had to add a dummy usage of the range element (like "(void) *It;" or similars) on the tests that had empty loops.
  6. I removed the braces from the CHECK comments. I think that there is no need for them, and they confuse vim.

Diff Detail

Event Timeline

angelgarcia updated this revision to Diff 34344.Sep 9 2015, 9:04 AM
angelgarcia retitled this revision from to Another patch for modernize-loop-convert..
angelgarcia updated this object.
angelgarcia added a reviewer: klimek.
angelgarcia added subscribers: cfe-commits, alexfh.
klimek added inline comments.Sep 10 2015, 2:15 AM
clang-tidy/modernize/LoopConvertCheck.cpp
457–458

I'd call that 'Usage' here, as it's not an iterator.

459–464

We need to document the members of Usage better: It seems unclear why the 'else' part goes into a lambda capture, or why in the if() path adding a '.' will ever help. Examples would help in comments here, I think.

clang-tidy/modernize/LoopConvertUtils.cpp
765–769

This needs to be a comment at the IsArrow field of Usage.

test/clang-tidy/modernize-loop-convert-basic.cpp
504

why Pseudo?

angelgarcia marked 4 inline comments as done.

Document Usage's fields and other comments.

klimek added inline comments.Sep 10 2015, 3:07 AM
clang-tidy/modernize/LoopConvertUtils.cpp
765–769

I think when the comment is on the Usage member, it's fine to delete it here, as it'll only get out of sync.

clang-tidy/modernize/LoopConvertUtils.h
214–217

I think this now really needs a different name, or we should put it into an enum if we can't find a good bool name that fits both the lambda capture and member expression case.

Replace the IsArrow field of Usage with an enum.

klimek added inline comments.Sep 10 2015, 4:01 AM
clang-tidy/modernize/LoopConvertCheck.cpp
468–470

Isn't it the other way round?

clang-tidy/modernize/LoopConvertUtils.h
200–205

Please comment the enumerators. Do we need default? Is that always a member expression or sometimes also something else?

Comment the enumerators.

Do we need default?

I think so. We need to set the cases that do not fall in any of these categories to something, and I think that using one of the other three as the default kind would be confusing. But maybe there is a better name than just UK_Default. Any ideas?

klimek accepted this revision.Sep 11 2015, 2:06 AM
klimek edited edge metadata.

Comment the enumerators.

Do we need default?

I think so. We need to set the cases that do not fall in any of these categories to something, and I think that using one of the other three as the default kind would be confusing. But maybe there is a better name than just UK_Default. Any ideas?

Can we perhaps just add a couple of example of other cases that are not member expressions? With that, LG.

This revision is now accepted and ready to land.Sep 11 2015, 2:06 AM
angelgarcia edited edge metadata.

Add examples of 'default' usages.

angelgarcia closed this revision.Sep 11 2015, 3:03 AM