[clang-tools-extra] Create a new check to look for mis-use in calls that take iterators (PR #99917)

Nathan James via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 29 09:57:32 PDT 2024


njames93 wrote:

> The `++` and `--` operators could be mis-used as well, similar to `+` and `-`. And there are some control statements with a single statement that has a compound statement around it, please remove those.

The `++` and `--` operators work on lvalues only(`std::end(Range)++` is usually a compiler error.), Therefore, in order to detect that, there would need to be some control flow logic in the check, Something along the lines of detecting setting a variable to `Range.end()` then looking for any calls to `operator++` on that variable. This logic definitely could be done and the results could catch many more questionable cases, but for the first version of this check I think it can be left out.

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


More information about the cfe-commits mailing list