[LifetimeSafety] Assertion failure for implicit lifetimebound in nested std namespace
I found this crash while working on https://github.com/llvm/llvm-project/pull/195231#issuecomment-4373047817
Reproducer: https://godbolt.org/z/KGz6zT6fT
This seems to happen when standard library code is compiled as ordinary user source rather than being treated as a system header, for example from a preprocessed repro. The repro attached in the linked comment does exactly that: it contains expanded libc++ code, so -Wlifetime-safety analyzes declarations that would normally be hidden behind <...> system headers.
The likely issue is that isInStlNamespace() only checks the immediate declaration context. For functions/classes nested below std through intermediate namespaces or records, the direct context is not necessarily the std namespace, so the STL guard returns false.
@llvm/issue-subscribers-clang-temporal-safety
Author: Zeyi Xu (zeyi2)
Reproducer: https://godbolt.org/z/KGz6zT6fT
The likely issue is that isInStlNamespace() only checks the immediate declaration context. For functions/classes nested below std through intermediate namespaces or records, the direct context is not necessarily the std namespace, so the STL guard returns false.
I'm not sure whether this crash is considered important enough to fix, since it appears to require preprocessed standard library code, but the assertion does seem reachable with a reduced repro.
If it is meaningful, I'd like to work on this issue myself.
Ohhh this is relatable! I remember encountering this, although not as a crash, but just getting an incorrect result from that function.
Oo. This looks important specially if it happens frequently.
We must remove the assert for now add a FIXME to add back later. Maybe the proper fix is to verify only "inferred" annotations and not which were added implicitly by special treatment.
Just my two cents here. I think this can be solved by walking the DeclContext chain in isInStlNamespace.