================
@@ -38,3 +29,21 @@ Example
 
   const S& s = fn(S{1});
   s.v; // use after free
+
+
+This issue can be resolved by declaring an overload of the problematic function
+where the ``const &`` parameter is instead declared as ``&&``. The developer 
has
+to ensure that the implementation of that function does not produce a
+use-after-free, the exact error that this check is warning against.
+Marking such an ``&&`` overload as ``deleted``, will silence the warning as 
+well. In the case of different ``const &`` parameters being returned depending
+on the control flow of the function, an overload where all problematic
+``const &`` parameters have been declared as ``&&`` will resolve the issue.
+
+This issue can also be resolved by adding ``[[clang::lifetimebound]]`` and
+enabling ``-Wdangling`` in clang. See `lifetimebound 
attribute<https://clang.llvm.org/docs/AttributeReference.html#id11>`_
+for details.
----------------
RedBeard0531 wrote:

`-Wdangling` is on by default now. Note that no flags are passed to clang and 
you still see the warning: https://godbolt.org/z/fz7sbPfqe

https://github.com/llvm/llvm-project/pull/118315
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to