[PATCH] D45679: [clang-tidy] Add a helper function isModified, that checks whether an expression is modified within a statement.

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 17 01:23:38 PDT 2018


JonasToth added a comment.

Short note here too: I think having `isModified` return a track record, like a vector for each

1. modifications
2. non-const handle taking
3. (const usages)

would be nice. Every user can decide how to react to it. Then the function would be more like `usageRecord` with pointers to each usage.
That allows graph building, it allows detailed diagnostics and contains all relevant information for the expr.

Other interesting cases we need to consider here:

1. casts -> all kinds of casts forbid kinda forbid constness.
2. rvalue references, modification happens for `std::move(v); std::forward(v); static_cast<T&&>(v)`
3. ternary operator
4. lambdas with local usage only
5. lambdas that escape, e.g. `int i; std::thread t([&](){ while(true) i++; });` Hard to analyze? I think we can consider all references into lambdas as escape

Maybe you can add an assertion about template types without concepts as a safeguard?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45679





More information about the cfe-commits mailing list