1 | // RUN: %check_clang_tidy %s performance-move-const-arg %t \ |
2 | // RUN: -config='{CheckOptions: \ |
3 | // RUN: {performance-move-const-arg.CheckMoveToConstRef: false}}' |
4 | |
5 | namespace std { |
6 | template <typename> |
7 | struct remove_reference; |
8 | |
9 | template <typename _Tp> |
10 | struct remove_reference { |
11 | typedef _Tp type; |
12 | }; |
13 | |
14 | template <typename _Tp> |
15 | struct remove_reference<_Tp &> { |
16 | typedef _Tp type; |
17 | }; |
18 | |
19 | template <typename _Tp> |
20 | struct remove_reference<_Tp &&> { |
21 | typedef _Tp type; |
22 | }; |
23 | |
24 | template <typename _Tp> |
25 | constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) { |
26 | return static_cast<typename std::remove_reference<_Tp>::type &&>(__t); |
27 | } |
28 | |
29 | template <typename _Tp> |
30 | constexpr _Tp && |
31 | forward(typename remove_reference<_Tp>::type &__t) noexcept { |
32 | return static_cast<_Tp &&>(__t); |
33 | } |
34 | |
35 | } // namespace std |
36 | |
37 | struct TriviallyCopyable { |
38 | int i; |
39 | }; |
40 | |
41 | void f(TriviallyCopyable) {} |
42 | |
43 | void g() { |
44 | TriviallyCopyable obj; |
45 | // Some basic test to ensure that other warnings from |
46 | // 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 | |
52 | class NoMoveSemantics { |
53 | public: |
54 | NoMoveSemantics(); |
55 | NoMoveSemantics(const NoMoveSemantics &); |
56 | NoMoveSemantics &operator=(const NoMoveSemantics &); |
57 | }; |
58 | |
59 | class MoveSemantics { |
60 | public: |
61 | MoveSemantics(); |
62 | MoveSemantics(MoveSemantics &&); |
63 | |
64 | MoveSemantics &operator=(MoveSemantics &&); |
65 | }; |
66 | |
67 | void callByConstRef1(const NoMoveSemantics &); |
68 | void callByConstRef2(const MoveSemantics &); |
69 | |
70 | void 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 | |