[clang-tools-extra] [NFC][clang-tidy]increase stability for bugprone-return-const-ref-from-parameter (PR #91160)
via cfe-commits
cfe-commits at lists.llvm.org
Sun May 5 19:59:28 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
@llvm/pr-subscribers-clang-tidy
Author: Congcong Cai (HerrCai0907)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/91160.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp (+6-3)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
index b3f7dd6d1c86f8..cacba38b4a5aa8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp
@@ -29,10 +29,13 @@ void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
void ReturnConstRefFromParameterCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *R = Result.Nodes.getNodeAs<ReturnStmt>("ret");
- diag(R->getRetValue()->getBeginLoc(),
- "returning a constant reference parameter may cause a use-after-free "
+ const SourceRange Range = R->getRetValue()->getSourceRange();
+ if (Range.isInvalid())
+ return;
+ diag(Range.getBegin(),
+ "returning a constant reference parameter may cause use-after-free "
"when the parameter is constructed from a temporary")
- << R->getRetValue()->getSourceRange();
+ << Range;
}
} // namespace clang::tidy::bugprone
``````````
</details>
https://github.com/llvm/llvm-project/pull/91160
More information about the cfe-commits
mailing list