New issue
Advanced search Search tips

Issue 895746 link

Starred by 2 users

Issue metadata

Status: Started
Owner:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug

Blocking:
issue 776257



Sign in to add a comment

Run clang-tidy's modernize-loop-convert check

Project Member Reported by jdoerrie@chromium.org, Oct 16

Issue description

From https://clang.llvm.org/extra/clang-tidy/checks/modernize-loop-convert.html:

This check converts for(...; ...; ...) loops to use the new range-based loops in C++11.

Three kinds of loops can be converted:

Loops over statically allocated arrays.
Loops over containers, using iterators.
Loops over array-like containers, using operator[] and at().


Examples:

Before:

for (int i = 0; i < N; ++i)
  cout << arr[i];

for (vector<int>::iterator it = v.begin(); it != v.end(); ++it)
  cout << *it;

for (int i = 0; i < v.size(); ++i)
  cout << v[i];

After:

for (auto & elem : arr)
  cout << elem;

for (auto & elem : v)
  cout << elem;

for (auto & elem : v)
  cout << elem;


Chrome Specific Notes and Options:
 - The default options for MaxCopySize (=16 bytes) and MinConfidence (="reasonable") are kept.
 - Renaming of non-aliased variables is disabled. While this useful in some cases, this can lead to variable names that are grammatically wrong (e.g. "entrie" or "addresse"), or violate the style guide (e.g. "kMyConstantElement"). 
 - In order to be compliant with clang-tidy checks, asterisks are added when iterating over containers of pointers.
 - Using fundamental types instead of auto is disabled, as this does not respect typedefs and rewrites size_t to unsigned long on a 64-bit machine.

The diff against clang-tidy/modernize/LoopConvertCheck.cpp [1] is attached.

[1] http://clang.llvm.org/extra/doxygen/LoopConvertCheck_8cpp_source.html
 
modernize-loop-convert.diff
1.4 KB Download
Project Member

Comment 1 by bugdroid1@chromium.org, Oct 22

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/6c6229357b371e0617bd9fcdaa0b17c92cc992f4

commit 6c6229357b371e0617bd9fcdaa0b17c92cc992f4
Author: jdoerrie <jdoerrie@chromium.org>
Date: Mon Oct 22 15:55:43 2018

[clang-tidy] Apply modernize-loop-convert in /base

This change applies clang-tidy's modernize-loop-convert [1] in /base.

Reproduction steps:
- run clang-tidy's modernize-loop-convert
- run git cl format
- manually remove unused constants due to -Wunused-const-variable

[1] https://clang.llvm.org/extra/clang-tidy/checks/modernize-loop-convert.html

This CL was uploaded by git cl split.

R=dcheng@chromium.org

Bug: 895746
Change-Id: I17cca09164d7ef795ae221994ecc65ca20abe0f2
Reviewed-on: https://chromium-review.googlesource.com/c/1282406
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601593}
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/containers/id_map_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/debug/proc_maps_linux_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/deferred_sequenced_task_runner.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/environment.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/files/file_path.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/files/file_path_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/files/file_util_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/json/json_reader_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/json/string_escape.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/json/string_escape_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/memory/shared_memory_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/observer_list_threadsafe_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/posix/global_descriptors.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/power_monitor/power_monitor_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/process/internal_linux.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/process/launch_posix.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/profiler/stack_sampling_profiler_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/rand_util_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/sha1.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/strings/string_number_conversions_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/strings/string_piece.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/strings/string_split_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/strings/string_util_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/strings/stringprintf_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/strings/sys_string_conversions_posix.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/strings/sys_string_conversions_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/strings/utf_offset_string_conversions.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/strings/utf_offset_string_conversions_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/strings/utf_string_conversions_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/synchronization/waitable_event_posix.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/synchronization/waitable_event_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/test/gtest_util.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/test/launcher/test_launcher.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/test/launcher/test_results_tracker.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/test/launcher/unit_test_launcher.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/test/power_monitor_test_base.h
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/test/trace_event_analyzer.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/test/trace_event_analyzer_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/threading/platform_thread_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/threading/thread_perftest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/timer/timer_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/version_unittest.cc
[modify] https://crrev.com/6c6229357b371e0617bd9fcdaa0b17c92cc992f4/base/vlog.cc

Project Member

Comment 2 by bugdroid1@chromium.org, Dec 6

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/812de1576d58185d036dc7483646b6b109d87e54

commit 812de1576d58185d036dc7483646b6b109d87e54
Author: jdoerrie <jdoerrie@chromium.org>
Date: Thu Dec 06 16:32:02 2018

[clang-tidy] Apply modernize-loop-convert in /base/i18n

This change applies clang-tidy's modernize-loop-convert [1] in /base/i18n.

Reproduction steps:
- run clang-tidy's modernize-loop-convert
- run git cl format
- manually remove unused constants due to -Wunused-const-variable

[1] https://clang.llvm.org/extra/clang-tidy/checks/modernize-loop-convert.html

This CL was uploaded by git cl split.

R=jshin@chromium.org

Bug: 895746
Change-Id: I9b9790b60aaca3f6afb2b4bd1109d800aec5b26a
Reviewed-on: https://chromium-review.googlesource.com/c/1282404
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Jungshik Shin <jshin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614377}
[modify] https://crrev.com/812de1576d58185d036dc7483646b6b109d87e54/base/i18n/break_iterator_unittest.cc
[modify] https://crrev.com/812de1576d58185d036dc7483646b6b109d87e54/base/i18n/build_utf8_validator_tables.cc
[modify] https://crrev.com/812de1576d58185d036dc7483646b6b109d87e54/base/i18n/file_util_icu_unittest.cc
[modify] https://crrev.com/812de1576d58185d036dc7483646b6b109d87e54/base/i18n/number_formatting_unittest.cc
[modify] https://crrev.com/812de1576d58185d036dc7483646b6b109d87e54/base/i18n/rtl_unittest.cc
[modify] https://crrev.com/812de1576d58185d036dc7483646b6b109d87e54/base/i18n/streaming_utf8_validator_perftest.cc
[modify] https://crrev.com/812de1576d58185d036dc7483646b6b109d87e54/base/i18n/streaming_utf8_validator_unittest.cc

Sign in to add a comment