[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 13 13:31:37 PST 2023


schenker wrote:

@PiotrZSL I changed some things, please take another look.

All const operator calls are now considered to be side-effect free. This also fixes some false-positives, e.g. 
```
struct t {
  int operator+=(int i) const { return i; }
} t;
assert(t += 1);
```
is no longer reported.

I added `<<` and `>>` to the list of operators with side-effects. 
Only const calls are reported, so 
```
std::stringstream ss;
assert(ss << 1);
```
is reported, but
```
assert(5 << 1);
```
is not.

There is no overlap with `CheckFunctionCalls`, `CXXOperatorCallExpr`s are not affected by the flag.

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


More information about the cfe-commits mailing list