Skip to content

[NFC][clang-tidy] document fix to bugprone-return-const-ref-from-parameter #107641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

5chmidti
Copy link
Contributor

@5chmidti 5chmidti commented Sep 6, 2024

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

…meter

Describe how the issue that is diagnosed by this check can be resolved.
Namely, by adding an overload for the xvalue case (`&&` parameter).

Fixes llvm#107600
@llvmbot
Copy link
Member

llvmbot commented Sep 6, 2024

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Julian Schmidt (5chmidti)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/107641.diff

1 Files Affected:

  • (modified) clang-tools-extra/docs/clang-tidy/checks/bugprone/return-const-ref-from-parameter.rst (+9)
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 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.
+
 Example
 -------
 

@5chmidti 5chmidti merged commit 4ef16e3 into llvm:main Sep 13, 2024
12 checks passed
@5chmidti 5chmidti deleted the clang_tidy_return_const_ref_docs branch September 13, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clang-tidy] Improve documentation of bugprone-return-const-ref-from-parameter
4 participants