[clang-tools-extra] [clang-tidy]bugprone-unused-return-value ignore `++` and `--` operator overloading (PR #84922)

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 14 08:57:32 PDT 2024


5chmidti wrote:

> @5chmidti What does `a new check diagnoses `it++`vs`++it` (where possible)` mean?

I mean this pattern:

```c++
void foo(std::string str) {
  auto iter = str.begin();
  iter++; // prefer ++iter;
  ++iter;

  sink(iter++);
  sink(++iter);

  for (auto i = str.begin(); i != str.end(); ++i) {}
  for (auto i = str.begin(); i != str.end(); i++) {} // prefer ++i
}
```

Where people write `i++` but they really mean `++i`. My question is if this check should ignore both of these cases, or if another check should detect this.

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


More information about the cfe-commits mailing list