81 lines · cpp
1// RUN: %check_clang_tidy %s performance-move-const-arg %t \2// RUN: -config='{CheckOptions: \3// RUN: {performance-move-const-arg.CheckMoveToConstRef: false}}'4 5namespace std {6template <typename>7struct remove_reference;8 9template <typename _Tp>10struct remove_reference {11 typedef _Tp type;12};13 14template <typename _Tp>15struct remove_reference<_Tp &> {16 typedef _Tp type;17};18 19template <typename _Tp>20struct remove_reference<_Tp &&> {21 typedef _Tp type;22};23 24template <typename _Tp>25constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) {26 return static_cast<typename std::remove_reference<_Tp>::type &&>(__t);27}28 29template <typename _Tp>30constexpr _Tp &&31forward(typename remove_reference<_Tp>::type &__t) noexcept {32 return static_cast<_Tp &&>(__t);33}34 35} // namespace std36 37struct TriviallyCopyable {38 int i;39};40 41void f(TriviallyCopyable) {}42 43void g() {44 TriviallyCopyable obj;45 // Some basic test to ensure that other warnings from46 // performance-move-const-arg are still working and enabled.47 f(std::move(obj));48 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable' has no effect; remove std::move() [performance-move-const-arg]49 // CHECK-FIXES: f(obj);50}51 52class NoMoveSemantics {53public:54 NoMoveSemantics();55 NoMoveSemantics(const NoMoveSemantics &);56 NoMoveSemantics &operator=(const NoMoveSemantics &);57};58 59class MoveSemantics {60public:61 MoveSemantics();62 MoveSemantics(MoveSemantics &&);63 64 MoveSemantics &operator=(MoveSemantics &&);65};66 67void callByConstRef1(const NoMoveSemantics &);68void callByConstRef2(const MoveSemantics &);69 70void moveToConstReferencePositives() {71 NoMoveSemantics a;72 73 // This call is now allowed since CheckMoveToConstRef is false.74 callByConstRef1(std::move(a));75 76 MoveSemantics b;77 78 // This call is now allowed since CheckMoveToConstRef is false.79 callByConstRef2(std::move(b));80}81