[PATCH] D82089: [clang-tidy] modernize-loop-convert reverse iteration support

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 18 06:30:07 PDT 2020


njames93 created this revision.
njames93 added reviewers: alexfh, Eugene.Zelenko, angelgarcia, aaron.ballman, klimek.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82089

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82089.271691.patch
Type: text/x-patch
Size: 23910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200618/038233a2/attachment-0001.bin>


More information about the cfe-commits mailing list