[all-commits] [llvm/llvm-project] 5229ed: [clang-tidy] fix modernize-loop-convert to retain ...

Nathan James via All-commits all-commits at lists.llvm.org
Sun Feb 7 08:37:41 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5229edd66742aeed407f774d77d437fa80347ad1
      https://github.com/llvm/llvm-project/commit/5229edd66742aeed407f774d77d437fa80347ad1
  Author: poelmanc <cpllvm at stellarscience.com>
  Date:   2021-02-07 (Sun, 07 Feb 2021)

  Changed paths:
    M clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
    A clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-multidimensional.cpp

  Log Message:
  -----------
  [clang-tidy] fix modernize-loop-convert to retain needed array-like operator[]

`modernize-loop-convert` handles //array-like// objects like vectors fairly well, but strips slightly too much information from the iteration expression by converting:
```
  Vector<Vector<int>> X;
  for (int J = 0; J < X[5].size(); ++J)
    copyArg(X[5][J]);
```
to
```
  Vector<Vector<int>> X;
  for (int J : X) // should be for (int J : X[5])
    copyArg(J);
```
The `[5]` is a call to `operator[]` and gets stripped by `LoopConvertCheck::getContainerString`. This patch fixes that and adds several test cases.

Reviewed By: njames93

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




More information about the All-commits mailing list