[clang-tools-extra] [NFC][clang-tidy]increase stability for bugprone-return-const-ref-from-parameter (PR #91160)
Congcong Cai via cfe-commits
cfe-commits at lists.llvm.org
Sun May 5 19:58:56 PDT 2024
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/91160
None
>From 8ba443f10a0fa65c319e5149a289d65f89a94d26 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Mon, 6 May 2024 10:58:23 +0800
Subject: [PATCH] [NFC][clang-tidy]increase stability for
bugprone-return-const-ref-from-parameter
---
.../bugprone/ReturnConstRefFromParameterCheck.cpp | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
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
More information about the cfe-commits
mailing list