================ @@ -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. ---------------- 5chmidti wrote:
> This issue can also be resolved by adding ``[[clang::lifetimebound]]``. > Enabling the ``-Wdangling`` warning in Clang is strongly advised, because it > detects mis-uses of the annotated function. See `lifetimebound > attribute<https://clang.llvm.org/docs/AttributeReference.html#id11>`_ for details. 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