[all-commits] [llvm/llvm-project] 8a548b: [clang-tidy] modernize-loop-convert reverse iterat...

Nathan James via All-commits all-commits at lists.llvm.org
Fri Oct 16 06:16:55 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 8a548bc203cfb0b2f830959cb7ec578c25512025
      https://github.com/llvm/llvm-project/commit/8a548bc203cfb0b2f830959cb7ec578c25512025
  Author: Nathan James <n.james93 at hotmail.co.uk>
  Date:   2020-10-16 (Fri, 16 Oct 2020)

  Changed paths:
    M clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
    M clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h
    M clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.h
    M clang-tools-extra/docs/ReleaseNotes.rst
    M clang-tools-extra/docs/clang-tidy/checks/modernize-loop-convert.rst
    A clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-reverse.cpp

  Log Message:
  -----------
  [clang-tidy] modernize-loop-convert reverse iteration support

Enables support for transforming loops of the form
```
for (auto I = Cont.rbegin(), E = Cont.rend(); I != E;++I)
```

This is done automatically in C++20 mode using `std::ranges::reverse_view` but there are options to specify a different function to reverse iterator over a container.
This is the first step, down the line I'd like to possibly extend this support for array based loops
```
for (unsigned I = Arr.size() - 1;I >=0;--I) Arr[I]...
```

Currently if you pass a reversing function with no header in the options it will just assume that the function exists, however as we have the ASTContext it may be as wise to check before applying, or at least lower the confidence level if we can't find it.

Reviewed By: alexfh

Differential Revision: https://reviews.llvm.org/D82089




More information about the All-commits mailing list