[clang] [LifetimeSafety] Use per-container invalidation rules to fix false positives (PR #183000)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 3 04:48:33 PST 2026
================
@@ -277,23 +277,89 @@ bool isContainerInvalidationMethod(const CXXMethodDecl &MD) {
if (!isInStlNamespace(RD))
return false;
- StringRef ContainerName = getName(*RD);
- static const llvm::StringSet<> Containers = {
- // Sequence
- "vector", "basic_string", "deque",
- // Adaptors
- // FIXME: Add queue and stack and check for underlying container (e.g. no
- // invalidation for std::list).
- "priority_queue",
- // Associative
- "set", "multiset", "map", "multimap",
- // Unordered Associative
- "unordered_set", "unordered_multiset", "unordered_map",
- "unordered_multimap",
- // C++23 Flat
- "flat_map", "flat_set", "flat_multimap", "flat_multiset"};
-
- if (!Containers.contains(ContainerName))
+ // `pop_back` is excluded: it only invalidates references to the removed
+ // element, not to other elements.
+ // https://en.cppreference.com/w/cpp/container/vector/pop_back.html
----------------
Xazax-hun wrote:
I think it is fine to keep one main link.
https://github.com/llvm/llvm-project/pull/183000
More information about the cfe-commits
mailing list