[clang-tools-extra] 4ef16e3 - [NFC][clang-tidy] document fix to bugprone-return-const-ref-from-parameter (#107641)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 13 10:05:26 PDT 2024
Author: Julian Schmidt
Date: 2024-09-13T19:05:23+02:00
New Revision: 4ef16e3160750717f447fd76e2383c10b68eb5ae
URL: https://github.com/llvm/llvm-project/commit/4ef16e3160750717f447fd76e2383c10b68eb5ae
DIFF: https://github.com/llvm/llvm-project/commit/4ef16e3160750717f447fd76e2383c10b68eb5ae.diff
LOG: [NFC][clang-tidy] document fix to bugprone-return-const-ref-from-parameter (#107641)
Describe how the issue that is diagnosed by this check can be resolved.
Namely, by adding an overload for the xvalue case (`&&` parameter).
Fixes #107600
Added:
Modified:
clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
Removed:
################################################################################
diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
index f007dfe5499908..2349e51477b7de 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst
@@ -12,6 +12,15 @@ after the call. When the function returns such a parameter also as constant refe
then the returned reference can be used after the object it refers to has been
destroyed.
+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
diff erent ``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.
+
Example
-------
More information about the cfe-commits
mailing list