[clang] [LifetimeSafety] Add UseFacts for function arguments and assignment RHS (PR #180446)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 07:03:39 PST 2026
================
@@ -260,9 +260,22 @@ void PointerToVectorElement() {
}
void SelfInvalidatingMap() {
- std::unordered_map<int, int> mp;
- mp[1] = 1;
- mp[2] = mp[1]; // FIXME: Detect this. We are mising a UseFact for the assignment params.
+ std::unordered_map<int, std::string> mp;
+ // TODO: We do not have a way to differentiate between pointer stability and iterator stability!
+ // std::unordered_map and other containers provide pointer/reference stability. Therefore the
+ // following is safe in practice.
+ // On the other hand, std::flat_hash_map (since C++23) does not provide pointer stability on
+ // insertion and following is unsafe for this container.
+ mp[1] = "42";
+ mp[2] = mp[1]; // expected-warning {{object whose reference is captured is later invalidated}} \
----------------
Xazax-hun wrote:
Oooh, I see! Okay, this makes sense. We sometimes have lvalues that do not correspond to any declarations. But we still know what storage are they referring to thanks to the annotations (built in or spelled out in source).
https://github.com/llvm/llvm-project/pull/180446
More information about the cfe-commits
mailing list