Skip to content

Commit 46ca05c

Browse files
committed
update docs
1 parent 9a2999d commit 46ca05c

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,19 +3923,37 @@ def LifetimeCaptureByDocs : Documentation {
39233923
let Content = [{
39243924
Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a function
39253925
parameter or implicit object parameter indicates that objects that are referred to by
3926-
that parameter may also be referred to by the capturing entity ``X``.
3926+
that parameter may also be referred to by a capturing entity ``X``.
39273927

3928-
By default:
3928+
Below is a list of types of the parameters and what they're considered to refer to:
39293929

3930-
- A reference is considered to refer to its referenced object.
3931-
- A pointer is considered to refer to its pointee.
3930+
- A reference param is considered to refer to its referenced object.
3931+
- A pointer param is considered to refer to its pointee.
39323932
- A ``std::initializer_list<T>`` is considered to refer to its underlying array.
39333933
- Aggregates (arrays and simple ``struct``\s) are considered to refer to all
39343934
objects that their transitive subobjects refer to.
3935-
- View types (types annotated with ``[[gsl::Pointer()]]``) are considered to refer
3936-
to its pointee. This holds true even if the view type appears as a reference.
3937-
For example, both ``std::string_view`` and ``const std::string_view &`` are
3938-
considered to refer to a ``std::string``.
3935+
- View type param (type annotated with ``[[gsl::Pointer()]]``) is considered to refer
3936+
to its pointee. This holds true even if the view type appears as a reference
3937+
in the parameter. For example, both ``std::string_view`` and
3938+
``const std::string_view &`` are considered to refer to a ``std::string``.
3939+
3940+
Clang would diagnose when a temporary object is used as an argument to such an
3941+
annotated parameter.
3942+
In this case, the capturing entity ``X`` could capture a dangling reference to this
3943+
temporary object.
3944+
3945+
.. code-block:: c++
3946+
3947+
void addToSet(std::string_view a [[clang::lifetime_capture_by(s)]], std::set<std::string_view>& s) {
3948+
s.insert(a);
3949+
}
3950+
void use() {
3951+
std::set<std::string_view> s;
3952+
addToSet(std::string(), s); // Warning: object whose reference is captured by 's' will be destroyed at the end of the full-expression.
3953+
// ^^^^^^^^^^^^^
3954+
std::string local;
3955+
addToSet(local, s); // Ok.
3956+
}
39393957

39403958
The capturing entity ``X`` can be one of the following:
39413959

@@ -3990,21 +4008,6 @@ The attribute supports specifying more than one capturing entities:
39904008
s2.insert(a);
39914009
}
39924010

3993-
Currently Clang would diagnose when a temporary is used as an argument to a
3994-
parameter whose reference is captured.
3995-
3996-
.. code-block:: c++
3997-
3998-
void addToSet(std::string_view a [[clang::lifetime_capture_by(s)]], std::set<std::string_view>& s) {
3999-
s.insert(a);
4000-
}
4001-
void use() {
4002-
std::set<std::string_view> s;
4003-
addToSet(std::string(), s); // Warning: object whose reference is captured by 's' will be destroyed at the end of the full-expression.
4004-
std::string local;
4005-
addToSet(local, s); // Ok.
4006-
}
4007-
40084011
.. _`lifetimebound`: https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
40094012
}];
40104013
}

0 commit comments

Comments
 (0)