[clang-tools-extra] [clang-tidy][modernize-use-std-erase] Replace iterator erase-remove idiom with std::(erase/erase_if) (PR #193407)

via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 26 02:19:47 PDT 2026


github-actions[bot] wrote:

<!--PREMERGE ADVISOR COMMENT: Linux-->
# :penguin: Linux x64 Test Results

* 3221 tests passed
* 7 tests skipped
* 1 test failed

## Failed Tests
(click on a test name to see its output)

### Clang Tools
<details>
<summary>Clang Tools.clang-tidy/checkers/modernize/use-std-erase.cpp</summary>

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/usr/bin/python3 /home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/../test/clang-tidy/check_clang_tidy.py -std=c++20 /home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-erase.cpp modernize-use-std-erase /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp
# executed command: /usr/bin/python3 /home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/../test/clang-tidy/check_clang_tidy.py -std=c++20 /home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-erase.cpp modernize-use-std-erase /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp
# .---command stdout------------
# | Running ['clang-tidy', '--experimental-custom-checks', '/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp', '-fix', '--checks=-*,modernize-use-std-erase', '--config={}', '--', '-std=c++20', '-nostdinc++', '-isystem', '/home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/../test/clang-tidy/checkers/Inputs/Headers/std']...
# | clang-tidy --experimental-custom-checks /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp -fix --checks=-*,modernize-use-std-erase --config={} -- -std=c++20 -nostdinc++ -isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/../test/clang-tidy/checkers/Inputs/Headers/std failed:
# | 2 warnings and 6 errors generated.
# | Error while processing /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp.
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp:33:5: warning: prefer std::erase over the erase-remove idiom [modernize-use-std-erase]
# |    33 |   v.erase(std::remove(v.begin(), v.end(), 42), v.end());
# |       |   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |       |   std::erase(v, 42)
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp:38:5: error: no member named 'erase' in 'std::deque<int>' [clang-diagnostic-error]
# |    38 |   d.erase(std::remove(d.begin(), d.end(), 42), d.end());
# |       |   ~ ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp:47:5: warning: prefer std::erase_if over the erase-remove_if idiom [modernize-use-std-erase]
# |    47 |   v.erase(std::remove_if(v.begin(), v.end(), IsNegative), v.end());
# |       |   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |       |   std::erase_if(v, IsNegative)
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp:52:5: error: no member named 'erase' in 'std::list<int>' [clang-diagnostic-error]
# |    52 |   l.erase(std::remove_if(l.begin(), l.end(), IsNegative), l.end());
# |       |   ~ ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp:59:5: error: no member named 'erase' in 'std::basic_string<char>' [clang-diagnostic-error]
# |    59 |   s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
# |       |   ~ ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp:59:25: error: no member named 'begin' in 'std::basic_string<char>' [clang-diagnostic-error]
# |    59 |   s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
# |       |                       ~ ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp:59:36: error: no member named 'end' in 'std::basic_string<char>' [clang-diagnostic-error]
# |    59 |   s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
# |       |                                  ~ ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp:59:51: error: no member named 'end' in 'std::basic_string<char>' [clang-diagnostic-error]
# |    59 |   s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
# |       |                                                 ~ ^
# | Found compiler errors, but -fix-errors was not specified.
# | Fixes have NOT been applied.
# | 
# | Found compiler error(s).
# | 
# `-----------------------------
# .---command stderr------------
# | Traceback (most recent call last):
# |   File "/home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/../test/clang-tidy/check_clang_tidy.py", line 554, in <module>
# |     main()
# |   File "/home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/../test/clang-tidy/check_clang_tidy.py", line 550, in main
# |     CheckRunner(args, extra_args).run()
# |   File "/home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/../test/clang-tidy/check_clang_tidy.py", line 426, in run
# |     clang_tidy_output = self.run_clang_tidy()
# |                         ^^^^^^^^^^^^^^^^^^^^^
# |   File "/home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/../test/clang-tidy/check_clang_tidy.py", line 289, in run_clang_tidy
# |     clang_tidy_output = try_run(args)
# |                         ^^^^^^^^^^^^^
# |   File "/home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/../test/clang-tidy/check_clang_tidy.py", line 64, in try_run
# |     process_output = subprocess.check_output(args, stderr=subprocess.STDOUT).decode(
# |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# |   File "/usr/lib/python3.12/subprocess.py", line 466, in check_output
# |     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
# |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# |   File "/usr/lib/python3.12/subprocess.py", line 571, in run
# |     raise CalledProcessError(retcode, process.args,
# | subprocess.CalledProcessError: Command '['clang-tidy', '--experimental-custom-checks', '/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test/clang-tidy/checkers/modernize/Output/use-std-erase.cpp.tmp.cpp', '-fix', '--checks=-*,modernize-use-std-erase', '--config={}', '--', '-std=c++20', '-nostdinc++', '-isystem', '/home/gha/actions-runner/_work/llvm-project/llvm-project/clang-tools-extra/test/../test/clang-tidy/checkers/Inputs/Headers/std']' returned non-zero exit status 1.
# `-----------------------------
# error: command failed with exit status: 1

--

```
</details>

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.

https://github.com/llvm/llvm-project/pull/193407


More information about the cfe-commits mailing list