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 99#include " LostStdMoveCheck.h"
1010#include " ../utils/DeclRefExprUtils.h"
1111#include " clang/ASTMatchers/ASTMatchFinder.h"
12+ #include " clang/Lex/Lexer.h"
1213
1314using namespace clang ::ast_matchers;
1415
@@ -111,7 +112,14 @@ void LostStdMoveCheck::check(const MatchFinder::MatchResult& Result) {
111112 return ;
112113 }
113114
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 ());
115123}
116124
117125} // 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)
2323{
2424 if (*ptr)
2525 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]
2727}
2828
2929void f_rvalue_ref (std::shared_ptr<int >&& ptr)
3030{
3131 if (*ptr)
3232 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]
3434}
3535
3636using SharedPtr = std::shared_ptr<int >;
3737void f_using (SharedPtr ptr)
3838{
3939 if (*ptr)
4040 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]
4242}
4343
4444void f_local ()
4545{
4646 std::shared_ptr<int > ptr;
4747 if (*ptr)
4848 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]
5050}
5151
5252void f_move ()
You can’t perform that action at this time.
0 commit comments