Files
clang-p2996/clang/lib/Sema/CheckExprLifetime.cpp
Haojian Wu 1374aa35a3 [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
2025-01-09 16:26:56 +01:00

63 KiB