[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 18 07:34:33 PST 2024
================
@@ -3922,16 +3922,41 @@ def LifetimeCaptureByDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a function
-parameter or implicit object parameter indicates that that objects that are referred to
-by that parameter may also be referred to by the capturing entity ``X``.
+parameter or implicit object parameter indicates that objects that are referred to by
+that parameter may also be referred to by a capturing entity ``X``.
+
+Below is a list of types of the parameters and what they're considered to refer to:
+
+- A reference param is considered to refer to its referenced object.
+- A pointer param is considered to refer to its pointee.
+- A ``std::initializer_list<T>`` is considered to refer to its underlying array.
+- Aggregates (arrays and simple ``struct``\s) are considered to refer to all
+ objects that their transitive subobjects refer to.
+- View type param (type annotated with ``[[gsl::Pointer()]]``) is considered to refer
+ to its pointee. This holds true even if the view type appears as a reference
+ in the parameter. For example, both ``std::string_view`` and
+ ``const std::string_view &`` are considered to refer to a ``std::string``.
+
+Clang would diagnose when a temporary object is used as an argument to such an
+annotated parameter.
----------------
usx95 wrote:
Yes. It is used to make the diagnostic more helpful.
Using it is not required for statement local analysis but can be useful for function local analysis.
The only case I can think of where argument to X could be useful is when that arg is itself a temporary. But in principle, the destructor of X could again use the captured values. So essentially, in all cases the captured arg should be non-temporary
https://github.com/llvm/llvm-project/pull/115921
More information about the cfe-commits
mailing list