Skip to content

Commit 401c775

Browse files
committed
fix doc
1 parent 91915f6 commit 401c775

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ using namespace clang::ast_matchers;
1515

1616
namespace clang::tidy::bugprone {
1717

18-
std::optional<TraversalKind>
19-
ReturnConstRefFromParameterCheck::getCheckTraversalKind() const {
20-
// Use 'AsIs' to make sure the return type is exactly the same as the
21-
// parameter type.
22-
return TK_AsIs;
23-
}
24-
2518
void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
2619
Finder->addMatcher(
2720
returnStmt(hasReturnValue(declRefExpr(to(parmVarDecl(hasType(

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
namespace clang::tidy::bugprone {
1515

16-
/// Detects the function which returns the const reference from parameter which
17-
/// causes potential use after free if the caller uses xvalue as argument.
16+
/// Detects the function which returns the const reference parameter as const
17+
/// reference. This might causes potential use after free errors if the caller
18+
/// uses xvalue as arguments.
1819
///
1920
/// For the user-facing documentation see:
2021
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/return-const-ref-from-parameter.html
@@ -24,7 +25,11 @@ class ReturnConstRefFromParameterCheck : public ClangTidyCheck {
2425
: ClangTidyCheck(Name, Context) {}
2526
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2627
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
27-
std::optional<TraversalKind> getCheckTraversalKind() const override;
28+
std::optional<TraversalKind> getCheckTraversalKind() const override {
29+
// Use 'AsIs' to make sure the return type is exactly the same as the
30+
// parameter type.
31+
return TK_AsIs;
32+
}
2833
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2934
return LangOpts.CPlusPlus;
3035
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
bugprone-return-const-ref-from-parameter
44
========================================
55

6-
Detects the function which returns the const reference from parameter which
7-
causes potential use after free if the caller uses xvalue as argument.
6+
Detects the function which returns the const reference parameter as const
7+
reference. This might causes potential use after free errors if the caller
8+
uses xvalue as arguments.
89

9-
In c++, const reference parameter can accept xvalue which will be destructed
10-
after the call. When the function returns this parameter also as const reference,
10+
In C++, const reference parameters can accept xvalues which will be destructed
11+
after the call. When the function returns such a parameter also as const reference,
1112
then the returned reference can be used after the object it refers to has been
1213
destroyed.
1314

0 commit comments

Comments
 (0)