File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 9
9
#include " LostStdMoveCheck.h"
10
10
#include " ../utils/DeclRefExprUtils.h"
11
11
#include " clang/ASTMatchers/ASTMatchFinder.h"
12
+ #include " clang/Lex/Lexer.h"
12
13
13
14
using namespace clang ::ast_matchers;
14
15
@@ -111,7 +112,14 @@ void LostStdMoveCheck::check(const MatchFinder::MatchResult& Result) {
111
112
return ;
112
113
}
113
114
114
- diag (LastUsage->getBeginLoc (), " could be std::move()" );
115
+
116
+ const SourceManager &Source = Result.Context ->getSourceManager ();
117
+ const auto Range = CharSourceRange::getTokenRange (LastUsage->getSourceRange ());
118
+ const StringRef NeedleExprCode = Lexer::getSourceText (
119
+ Range, Source,
120
+ Result.Context ->getLangOpts ());
121
+ diag (LastUsage->getBeginLoc (), " could be std::move()" )
122
+ << FixItHint::CreateReplacement (Range, (" std::move(" + NeedleExprCode + " )" ).str ());
115
123
}
116
124
117
125
} // namespace clang::tidy::performance
Original file line number Diff line number Diff line change @@ -23,30 +23,30 @@ void f_arg(std::shared_ptr<int> ptr)
23
23
{
24
24
if (*ptr)
25
25
f (ptr);
26
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Could be std::move() [performance-lost-std-move]
26
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: could be std::move() [performance-lost-std-move]
27
27
}
28
28
29
29
void f_rvalue_ref (std::shared_ptr<int >&& ptr)
30
30
{
31
31
if (*ptr)
32
32
f (ptr);
33
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Could be std::move() [performance-lost-std-move]
33
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: could be std::move() [performance-lost-std-move]
34
34
}
35
35
36
36
using SharedPtr = std::shared_ptr<int >;
37
37
void f_using (SharedPtr ptr)
38
38
{
39
39
if (*ptr)
40
40
f (ptr);
41
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Could be std::move() [performance-lost-std-move]
41
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: could be std::move() [performance-lost-std-move]
42
42
}
43
43
44
44
void f_local ()
45
45
{
46
46
std::shared_ptr<int > ptr;
47
47
if (*ptr)
48
48
f (ptr);
49
- // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: Could be std::move() [performance-lost-std-move]
49
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: could be std::move() [performance-lost-std-move]
50
50
}
51
51
52
52
void f_move ()
You can’t perform that action at this time.
0 commit comments