Page MenuHomePhabricator

[clang-tidy] Add modernize-use-ranges check.
Needs ReviewPublic

Authored by njames93 on Jun 16 2020, 3:59 AM.

Details

Summary

Flags and replaces calls to standard library algorithms that could be converted to use the std::ranges algorithms introduced in c++20.

Diff Detail

Event Timeline

njames93 created this revision.Jun 16 2020, 3:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2020, 3:59 AM

great to see such a check!

clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
78

i would at rbegin() and the likes, too.

njames93 marked an inline comment as done.Jun 16 2020, 5:52 AM
njames93 added inline comments.
clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
78

How should rbegin be handled
std::<func>(std::rbegin(X), std::rbegin(X)) -> std::ranges::<func>(std::ranges::reverse_view(X)) I almost think that looks less pleasing, but thats just my opinion.

Eugene.Zelenko added inline comments.
clang-tools-extra/docs/ReleaseNotes.rst
74

Please highlight std::ranges with double back-ticks.

clang-tools-extra/docs/clang-tidy/checks/modernize-use-ranges.rst
7

Please synchronize with description in Release Notes.

9

C++20.

22

C++20.

23

Single back-ticks for command-line options.

njames93 updated this revision to Diff 271191.Jun 16 2020, 1:58 PM
njames93 marked 4 inline comments as done.

Tweaked documentation

njames93 marked an inline comment as done.Jun 16 2020, 1:59 PM
njames93 updated this revision to Diff 271855.Jun 18 2020, 2:55 PM

Added IncludeInserter to include the <ranges> header.
Added support for reverse iteration controlled by config.
Added support for begin/end calls via pointers.
Made the begin/end call matcher more robust if other checks want to use it down the line.
Moved the std lib parts out of the test case into header files.

njames93 updated this revision to Diff 272033.Jun 19 2020, 5:45 AM
  • Updated Docs and set HandleReverseRanges default to false