You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang] Don't infer lifetime_capture-by for reference of raw pointer types. (#122240)
When a vector is instantiated with a pointer type (`T` being `const
Foo*`), the inferred annotation becomes `push_back(const Foo*& value
[[clang::lifetime_capture_by(this)]])`.
For reference parameters, the `lifetime_capture_by` attribute treats the
lifetime as referring to the referenced object -- in this case, the
**pointer** itself, not the pointee object. In the `push_back`, we copy
the pointer's value, which does not establish a reference to the
pointer. This behavior is safe and does not capture the pointer's
lifetime.
The annotation should not be inferred for cases where `T` is a pointer
type, as the intended semantics do not align with the annotation.
Fixes#121391
Copy file name to clipboardExpand all lines: clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
+22-1Lines changed: 22 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -406,7 +406,7 @@ void use() {
406
406
strings.insert(strings.begin(), std::string());
407
407
408
408
std::vector<const std::string*> pointers;
409
-
pointers.push_back(getLifetimeBoundPointer(std::string()));// expected-warning {{object whose reference is captured by 'pointers' will be destroyed at the end of the full-expression}}
0 commit comments