Skip to content

Commit 37a518b

Browse files
committed
[clang-tidy] fix false positive in bugprone-return-const-ref-from-parameter
1 parent 67cb040 commit 37a518b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
2121
to(parmVarDecl(hasType(hasCanonicalType(
2222
qualType(lValueReferenceType(pointee(
2323
qualType(isConstQualified()))))
24-
.bind("type"))))
24+
.bind("type"))), parmVarDecl(hasDeclContext(functionDecl().bind("owner"))))
2525
.bind("param")))),
2626
hasAncestor(
27-
functionDecl(hasReturnTypeLoc(loc(qualType(
27+
functionDecl(equalsBoundNode("owner"), hasReturnTypeLoc(loc(qualType(
2828
hasCanonicalType(equalsBoundNode("type"))))))
2929
.bind("func")))
3030
.bind("ret"),

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ New check aliases
104104
Changes in existing checks
105105
^^^^^^^^^^^^^^^^^^^^^^^^^^
106106

107+
- Improved :doc:`bugprone-return-const-ref-from-parameter
108+
<clang-tidy/checks/bugprone/return-const-ref-from-parameter>` check by no longer
109+
giving false positives for lambda.
110+
107111
- Improved :doc:`readability-redundant-smartptr-get
108112
<clang-tidy/checks/readability/redundant-smartptr-get>` check to
109113
remove `->`, when reduntant `get()` is removed.

clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ void instantiate(const int &param, const float &paramf, int &mut_param, float &m
142142
itf6(mut_paramf);
143143
}
144144

145+
template<class T>
146+
void f(const T& t) {
147+
const auto get = [&t] -> const T& { return t; };
148+
return T{};
149+
}
150+
145151
} // namespace valid
146152

147153
namespace overload {

0 commit comments

Comments
 (0)