<div dir="ltr"><div dir="ltr">On Mon, 22 Mar 2021 at 13:31, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Thu, Mar 18, 2021 at 7:58 PM Richard Smith via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Author: Richard Smith<br>
Date: 2021-03-18T19:58:21-07:00<br>
New Revision: 5c689e4bb0473e08645547ddbf9874b5e2fa04d0<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/5c689e4bb0473e08645547ddbf9874b5e2fa04d0" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/5c689e4bb0473e08645547ddbf9874b5e2fa04d0</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/5c689e4bb0473e08645547ddbf9874b5e2fa04d0.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/5c689e4bb0473e08645547ddbf9874b5e2fa04d0.diff</a><br>
<br>
LOG: Improve documentation for the [[clang::lifetimebound]] attribute.<br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
clang/include/clang/Basic/AttrDocs.td<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td<br>
index f73fbd08e3bf..734cf026ae87 100644<br>
--- a/clang/include/clang/Basic/AttrDocs.td<br>
+++ b/clang/include/clang/Basic/AttrDocs.td<br>
@@ -3032,10 +3032,39 @@ is retained by the return value of the annotated function<br>
(or, for a parameter of a constructor, in the value of the constructed object).<br>
It is only supported in C++.<br>
<br>
-This attribute provides an experimental implementation of the facility<br>
-described in the C++ committee paper `P0936R0 <<a href="http://wg21.link/p0936r0" rel="noreferrer" target="_blank">http://wg21.link/p0936r0</a>>`_,<br>
-and is subject to change as the design of the corresponding functionality<br>
-changes.<br>
+This attribute causes warnings to be produced if a temporary object does not<br>
+live long enough. For example:<br>
+<br>
+.. code-block:: c++<br>
+<br>
+ template<typename T, typename U><br>
+ const U &get_or_default(std::map<T, U> &m, const T &key,<br>
+ const U &default_value [[clang::lifetimebound]]);<br>
+<br>
+ std::map<std::string, std::string> m;<br>
+ // warning: temporary "bar"s that might be bound to local reference 'val'<br>
+ // will be destroyed at the end of the full-expression<br>
+ const std::string &val = get_or_default(m, "foo"s, "bar"s);<br>
+<br>
+When applied to a reference parameter, the referenced object is assumed to be<br>
+retained by the return value of the function. When applied to a non-reference<br>
+parameter (for example, a pointer or a class type), all temporaries referenced<br>
+by the parameter are assumed to be retained by the return value of the<br>
+function.<br></blockquote><div><br>"referenced by" seems a bit vague to me - I guess it means all reference members of the parameter? (what about reference members of subobjects?)<br></div></div></div></blockquote><div><br></div><div>I'll send you a further improvement to review :)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+The attribute can be applied to the implicit ``this`` parameter of a member<br>
+function by writing the attribute after the function type:<br>
+<br>
+.. code-block:: c++<br>
+<br>
+ struct string_view {<br>
+ // ...<br>
+ const char *data() const [[clang::lifetimebound]];<br>
+ };<br>
+<br>
+This attribute is inspired by the C++ committee paper `P0936R0<br>
+<<a href="http://wg21.link/p0936r0" rel="noreferrer" target="_blank">http://wg21.link/p0936r0</a>>`_, but does not affect whether temporary objects<br>
+have their lifetimes extended.<br>
}];<br>
}<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div>
</blockquote></div></div>