File tree Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Original file line number Diff line number Diff line change @@ -15,13 +15,6 @@ using namespace clang::ast_matchers;
15
15
16
16
namespace clang ::tidy::bugprone {
17
17
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
-
25
18
void ReturnConstRefFromParameterCheck::registerMatchers (MatchFinder *Finder) {
26
19
Finder->addMatcher (
27
20
returnStmt (hasReturnValue (declRefExpr (to (parmVarDecl (hasType (
Original file line number Diff line number Diff line change 13
13
14
14
namespace clang ::tidy::bugprone {
15
15
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.
18
19
// /
19
20
// / For the user-facing documentation see:
20
21
// / http://clang.llvm.org/extra/clang-tidy/checks/bugprone/return-const-ref-from-parameter.html
@@ -24,7 +25,11 @@ class ReturnConstRefFromParameterCheck : public ClangTidyCheck {
24
25
: ClangTidyCheck(Name, Context) {}
25
26
void registerMatchers (ast_matchers::MatchFinder *Finder) override ;
26
27
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
+ }
28
33
bool isLanguageVersionSupported (const LangOptions &LangOpts) const override {
29
34
return LangOpts.CPlusPlus ;
30
35
}
Original file line number Diff line number Diff line change 3
3
bugprone-return-const-ref-from-parameter
4
4
========================================
5
5
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.
8
9
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,
11
12
then the returned reference can be used after the object it refers to has been
12
13
destroyed.
13
14
You can’t perform that action at this time.
0 commit comments