================
@@ -172,6 +172,29 @@ Without ``[[clang::lifetimebound]]`` on ``getView()``, the
analysis would not
know that the value returned by ``getView()`` depends on the temporary
``MyOwner`` object, and it would not be able to diagnose the dangling ``sv``.
+The analysis also tracks record types returned from functions and constructors
+with ``[[clang::lifetimebound]]`` annotated parameters:
+
+.. code-block:: c++
+
+ #include <string>
+
+ struct S {
+ S(const std::string &s [[clang::lifetimebound]]);
+ };
+
+ S getS(const std::string &s [[clang::lifetimebound]]);
+
+ void test() {
+ S a(std::string("temp")); // warning: object whose reference is captured
does not live long enough
+ // note: destroyed here
+ (void)a; // note: later used here
+
+ S b = getS(std::string("temp")); // warning: object whose reference is
captured does not live long enough
+ // note: destroyed here
+ (void)b; // note: later used here
+ }
----------------
usx95 wrote:
Consider expanding this example to a multi-line use-after-scope scenarios
instead of temporaries
https://github.com/llvm/llvm-project/pull/189508
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits