Skip to content

Commit 4ef16e3

Browse files
authored
[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
1 parent b9d85b1 commit 4ef16e3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ after the call. When the function returns such a parameter also as constant refe
1212
then the returned reference can be used after the object it refers to has been
1313
destroyed.
1414

15+
This issue can be resolved by declaring an overload of the problematic function
16+
where the ``const &`` parameter is instead declared as ``&&``. The developer has
17+
to ensure that the implementation of that function does not produce a
18+
use-after-free, the exact error that this check is warning against.
19+
Marking such an ``&&`` overload as ``deleted``, will silence the warning as
20+
well. In the case of different ``const &`` parameters being returned depending
21+
on the control flow of the function, an overload where all problematic
22+
``const &`` parameters have been declared as ``&&`` will resolve the issue.
23+
1524
Example
1625
-------
1726

0 commit comments

Comments
 (0)