1c491c917SChris Cotter // RUN: %check_clang_tidy -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
21af159e9SPiotr Zegar // RUN: -config="{CheckOptions: {cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: true}}" -- -fno-delayed-template-parsing
3c491c917SChris Cotter // RUN: %check_clang_tidy -check-suffix=,CXX14 -std=c++14 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
41af159e9SPiotr Zegar // RUN: -config="{CheckOptions: {cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: true}}" -- -fno-delayed-template-parsing
5c491c917SChris Cotter // RUN: %check_clang_tidy -check-suffix=,NOSUBEXPR -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
61af159e9SPiotr Zegar // RUN: -config="{CheckOptions: {cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: false, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: true}}" -- -fno-delayed-template-parsing
7c491c917SChris Cotter // RUN: %check_clang_tidy -check-suffix=,UNNAMED -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
81af159e9SPiotr Zegar // RUN: -config="{CheckOptions: {cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams: false, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: true}}" -- -fno-delayed-template-parsing
9c491c917SChris Cotter // RUN: %check_clang_tidy -check-suffix=,NONDEDUCED -std=c++11 %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- \
101af159e9SPiotr Zegar // RUN: -config="{CheckOptions: {cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams: true, cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreNonDeducedTemplateTypes: false}}" -- -fno-delayed-template-parsing
11c491c917SChris Cotter 
12c491c917SChris Cotter // NOLINTBEGIN
13c491c917SChris Cotter namespace std {
14c491c917SChris Cotter template <typename>
15c491c917SChris Cotter struct remove_reference;
16c491c917SChris Cotter 
17c491c917SChris Cotter template <typename _Tp> struct remove_reference { typedef _Tp type; };
18c491c917SChris Cotter template <typename _Tp> struct remove_reference<_Tp&> { typedef _Tp type; };
19c491c917SChris Cotter template <typename _Tp> struct remove_reference<_Tp&&> { typedef _Tp type; };
20c491c917SChris Cotter 
21c491c917SChris Cotter template <typename _Tp>
22c491c917SChris Cotter constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept;
23c491c917SChris Cotter 
24c491c917SChris Cotter template <typename _Tp>
25c491c917SChris Cotter constexpr _Tp &&
26c491c917SChris Cotter forward(typename remove_reference<_Tp>::type &__t) noexcept;
27c491c917SChris Cotter 
28c491c917SChris Cotter }
29c491c917SChris Cotter // NOLINTEND
30c491c917SChris Cotter 
31c491c917SChris Cotter struct Obj {
32c491c917SChris Cotter   Obj();
33c491c917SChris Cotter   Obj(const Obj&);
34c491c917SChris Cotter   Obj& operator=(const Obj&);
35c491c917SChris Cotter   Obj(Obj&&);
36c491c917SChris Cotter   Obj& operator=(Obj&&);
37c491c917SChris Cotter   void member() const;
38c491c917SChris Cotter };
39c491c917SChris Cotter 
40c491c917SChris Cotter void consumes_object(Obj);
41c491c917SChris Cotter 
never_moves_param(Obj && o)42c491c917SChris Cotter void never_moves_param(Obj&& o) {
43c491c917SChris Cotter   // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
44c491c917SChris Cotter   o.member();
45c491c917SChris Cotter }
46c491c917SChris Cotter 
47c491c917SChris Cotter void just_a_declaration(Obj&& o);
48c491c917SChris Cotter 
copies_object(Obj && o)49c491c917SChris Cotter void copies_object(Obj&& o) {
50c491c917SChris Cotter   // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
51c491c917SChris Cotter   Obj copy = o;
52c491c917SChris Cotter }
53c491c917SChris Cotter 
54c491c917SChris Cotter template <typename T>
never_moves_param_template(Obj && o,T t)55c491c917SChris Cotter void never_moves_param_template(Obj&& o, T t) {
56c491c917SChris Cotter   // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
57c491c917SChris Cotter   o.member();
58c491c917SChris Cotter }
59c491c917SChris Cotter 
never_moves_params(Obj && o1,Obj && o2)60c491c917SChris Cotter void never_moves_params(Obj&& o1, Obj&& o2) {
61c491c917SChris Cotter   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: rvalue reference parameter 'o1' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
62c491c917SChris Cotter   // CHECK-MESSAGES: :[[@LINE-2]]:41: warning: rvalue reference parameter 'o2' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
63c491c917SChris Cotter }
64c491c917SChris Cotter 
never_moves_some_params(Obj && o1,Obj && o2)65c491c917SChris Cotter void never_moves_some_params(Obj&& o1, Obj&& o2) {
66c491c917SChris Cotter   // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: rvalue reference parameter 'o1' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
67c491c917SChris Cotter 
68c491c917SChris Cotter   Obj other{std::move(o2)};
69c491c917SChris Cotter }
70c491c917SChris Cotter 
never_moves_unnamed(Obj &&)71c491c917SChris Cotter void never_moves_unnamed(Obj&&) {}
72c491c917SChris Cotter // CHECK-MESSAGES-UNNAMED: :[[@LINE-1]]:31: warning: rvalue reference parameter '' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
73c491c917SChris Cotter 
never_moves_mixed(Obj o1,Obj && o2)74c491c917SChris Cotter void never_moves_mixed(Obj o1, Obj&& o2) {
75c491c917SChris Cotter   // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: rvalue reference parameter 'o2' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
76c491c917SChris Cotter }
77c491c917SChris Cotter 
lambda_captures_parameter_as_value(Obj && o)78c491c917SChris Cotter void lambda_captures_parameter_as_value(Obj&& o) {
79c491c917SChris Cotter   auto f = [o]() {
80c491c917SChris Cotter     consumes_object(std::move(o));
81c491c917SChris Cotter   };
82c491c917SChris Cotter   // CHECK-MESSAGES: :[[@LINE-4]]:47: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
83c491c917SChris Cotter }
84c491c917SChris Cotter 
lambda_captures_parameter_as_value_nested(Obj && o)85c491c917SChris Cotter void lambda_captures_parameter_as_value_nested(Obj&& o) {
86c491c917SChris Cotter   // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
87c491c917SChris Cotter   auto f = [&o]() {
88c491c917SChris Cotter     auto f_nested = [o]() {
89c491c917SChris Cotter       consumes_object(std::move(o));
90c491c917SChris Cotter     };
91c491c917SChris Cotter   };
92c491c917SChris Cotter   auto f2 = [o]() {
93c491c917SChris Cotter     auto f_nested = [&o]() {
94c491c917SChris Cotter       consumes_object(std::move(o));
95c491c917SChris Cotter     };
96c491c917SChris Cotter   };
97c491c917SChris Cotter   auto f3 = [o]() {
98c491c917SChris Cotter     auto f_nested = [&o]() {
99c491c917SChris Cotter       auto f_nested_inner = [&o]() {
100c491c917SChris Cotter         consumes_object(std::move(o));
101c491c917SChris Cotter       };
102c491c917SChris Cotter     };
103c491c917SChris Cotter   };
104c491c917SChris Cotter   auto f4 = [&o]() {
105c491c917SChris Cotter     auto f_nested = [&o]() {
106c491c917SChris Cotter       auto f_nested_inner = [o]() {
107c491c917SChris Cotter         consumes_object(std::move(o));
108c491c917SChris Cotter       };
109c491c917SChris Cotter     };
110c491c917SChris Cotter   };
111c491c917SChris Cotter }
112c491c917SChris Cotter 
misc_lambda_checks()113c491c917SChris Cotter void misc_lambda_checks() {
114c491c917SChris Cotter   auto never_moves = [](Obj&& o1) {
115c491c917SChris Cotter     Obj other{o1};
116c491c917SChris Cotter   };
117c491c917SChris Cotter   // CHECK-MESSAGES: :[[@LINE-3]]:31: warning: rvalue reference parameter 'o1' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
118c491c917SChris Cotter 
119c491c917SChris Cotter #if __cplusplus >= 201402L
120c491c917SChris Cotter   auto never_moves_with_auto_param = [](Obj&& o1, auto& v) {
121c491c917SChris Cotter     Obj other{o1};
122c491c917SChris Cotter   };
123c491c917SChris Cotter   // CHECK-MESSAGES-CXX14: :[[@LINE-3]]:47: warning: rvalue reference parameter 'o1' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
124c491c917SChris Cotter #endif
125c491c917SChris Cotter }
126c491c917SChris Cotter 
127c491c917SChris Cotter template <typename T>
forwarding_ref(T && t)128c491c917SChris Cotter void forwarding_ref(T&& t) {
129c491c917SChris Cotter   t.member();
130c491c917SChris Cotter }
131c491c917SChris Cotter 
132c491c917SChris Cotter template <typename T>
forwarding_ref_forwarded(T && t)133c491c917SChris Cotter void forwarding_ref_forwarded(T&& t) {
134c491c917SChris Cotter   forwarding_ref(std::forward<T>(t));
135c491c917SChris Cotter }
136c491c917SChris Cotter 
137c491c917SChris Cotter template <typename... Ts>
type_pack(Ts &&...ts)138c491c917SChris Cotter void type_pack(Ts&&... ts) {
139c491c917SChris Cotter   (forwarding_ref(std::forward<Ts>(ts)), ...);
140c491c917SChris Cotter }
141c491c917SChris Cotter 
call_forwarding_functions()142c491c917SChris Cotter void call_forwarding_functions() {
143c491c917SChris Cotter   Obj o;
144c491c917SChris Cotter 
145c491c917SChris Cotter   forwarding_ref(Obj{});
146c491c917SChris Cotter   type_pack(Obj{});
147c491c917SChris Cotter   type_pack(Obj{}, o);
148c491c917SChris Cotter   type_pack(Obj{}, Obj{});
149c491c917SChris Cotter }
150c491c917SChris Cotter 
moves_parameter(Obj && o)151c491c917SChris Cotter void moves_parameter(Obj&& o) {
152c491c917SChris Cotter   Obj moved = std::move(o);
153c491c917SChris Cotter }
154c491c917SChris Cotter 
moves_parameter_extra_parens(Obj && o)155c491c917SChris Cotter void moves_parameter_extra_parens(Obj&& o) {
156c491c917SChris Cotter   Obj moved = std::move((o));
157c491c917SChris Cotter }
158c491c917SChris Cotter 
does_not_move_in_evaluated(Obj && o)159bd762846SChris Cotter void does_not_move_in_evaluated(Obj&& o) {
160bd762846SChris Cotter   // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
161bd762846SChris Cotter   using result_t = decltype(std::move(o));
162bd762846SChris Cotter   unsigned size = sizeof(std::move(o));
163bd762846SChris Cotter   Obj moved = o;
164bd762846SChris Cotter }
165bd762846SChris Cotter 
166c491c917SChris Cotter template <typename T1, typename T2>
167c491c917SChris Cotter struct mypair {
168c491c917SChris Cotter   T1 first;
169c491c917SChris Cotter   T2 second;
170c491c917SChris Cotter };
171c491c917SChris Cotter 
moves_member_of_parameter(mypair<Obj,Obj> && pair)172c491c917SChris Cotter void moves_member_of_parameter(mypair<Obj, Obj>&& pair) {
173c491c917SChris Cotter   // CHECK-MESSAGES-NOSUBEXPR: :[[@LINE-1]]:51: warning: rvalue reference parameter 'pair' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
174c491c917SChris Cotter   Obj a = std::move(pair.first);
175c491c917SChris Cotter   Obj b = std::move(pair.second);
176c491c917SChris Cotter }
177c491c917SChris Cotter 
178c491c917SChris Cotter template <typename T>
179c491c917SChris Cotter struct myoptional {
180c491c917SChris Cotter   T& operator*() &;
181c491c917SChris Cotter   T&& operator*() &&;
182c491c917SChris Cotter };
183c491c917SChris Cotter 
moves_deref_optional(myoptional<Obj> && opt)184c491c917SChris Cotter void moves_deref_optional(myoptional<Obj>&& opt) {
185c491c917SChris Cotter   // CHECK-MESSAGES-NOSUBEXPR: :[[@LINE-1]]:45: warning: rvalue reference parameter 'opt' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
186c491c917SChris Cotter   Obj other = std::move(*opt);
187c491c917SChris Cotter }
188c491c917SChris Cotter 
moves_optional_then_deref_resulting_rvalue(myoptional<Obj> && opt)189c491c917SChris Cotter void moves_optional_then_deref_resulting_rvalue(myoptional<Obj>&& opt) {
190c491c917SChris Cotter   Obj other = *std::move(opt);
191c491c917SChris Cotter }
192c491c917SChris Cotter 
pass_by_lvalue_reference(Obj & o)193c491c917SChris Cotter void pass_by_lvalue_reference(Obj& o) {
194c491c917SChris Cotter   o.member();
195c491c917SChris Cotter }
196c491c917SChris Cotter 
pass_by_value(Obj o)197c491c917SChris Cotter void pass_by_value(Obj o) {
198c491c917SChris Cotter   o.member();
199c491c917SChris Cotter }
200c491c917SChris Cotter 
pass_by_const_lvalue_reference(const Obj & o)201c491c917SChris Cotter void pass_by_const_lvalue_reference(const Obj& o) {
202c491c917SChris Cotter   o.member();
203c491c917SChris Cotter }
204c491c917SChris Cotter 
pass_by_const_lvalue_reference(const Obj && o)205c491c917SChris Cotter void pass_by_const_lvalue_reference(const Obj&& o) {
206c491c917SChris Cotter   o.member();
207c491c917SChris Cotter }
208c491c917SChris Cotter 
lambda_captures_parameter_as_reference(Obj && o)209c491c917SChris Cotter void lambda_captures_parameter_as_reference(Obj&& o) {
210c491c917SChris Cotter   auto f = [&o]() {
211c491c917SChris Cotter     consumes_object(std::move(o));
212c491c917SChris Cotter   };
213c491c917SChris Cotter }
214c491c917SChris Cotter 
lambda_captures_parameter_as_reference_nested(Obj && o)215c491c917SChris Cotter void lambda_captures_parameter_as_reference_nested(Obj&& o) {
216c491c917SChris Cotter   auto f = [&o]() {
217c491c917SChris Cotter     auto f_nested = [&o]() {
218c491c917SChris Cotter       auto f_nested2 = [&o]() {
219c491c917SChris Cotter         consumes_object(std::move(o));
220c491c917SChris Cotter       };
221c491c917SChris Cotter     };
222c491c917SChris Cotter   };
223c491c917SChris Cotter }
224c491c917SChris Cotter 
225c491c917SChris Cotter #if __cplusplus >= 201402L
lambda_captures_parameter_generalized(Obj && o)226c491c917SChris Cotter void lambda_captures_parameter_generalized(Obj&& o) {
227c491c917SChris Cotter   auto f = [o = std::move(o)]() {
228c491c917SChris Cotter     consumes_object(std::move(o));
229c491c917SChris Cotter   };
230c491c917SChris Cotter }
231c491c917SChris Cotter #endif
232c491c917SChris Cotter 
negative_lambda_checks()233c491c917SChris Cotter void negative_lambda_checks() {
234c491c917SChris Cotter   auto never_moves_nested = [](Obj&& o1) {
235c491c917SChris Cotter     auto nested = [&]() {
236c491c917SChris Cotter       Obj other{std::move(o1)};
237c491c917SChris Cotter     };
238c491c917SChris Cotter   };
239c491c917SChris Cotter 
240c491c917SChris Cotter #if __cplusplus >= 201402L
241c491c917SChris Cotter   auto auto_lvalue_ref_param = [](auto& o1) {
242c491c917SChris Cotter     Obj other{o1};
243c491c917SChris Cotter   };
244c491c917SChris Cotter 
245c491c917SChris Cotter   auto auto_forwarding_ref_param = [](auto&& o1) {
246c491c917SChris Cotter     Obj other{o1};
247c491c917SChris Cotter   };
248c491c917SChris Cotter 
249c491c917SChris Cotter   auto does_move_auto_rvalue_ref_param = [](auto&& o1) {
250c491c917SChris Cotter     Obj other{std::forward(o1)};
251c491c917SChris Cotter   };
252c491c917SChris Cotter #endif
253c491c917SChris Cotter 
254c491c917SChris Cotter   auto does_move = [](Obj&& o1) {
255c491c917SChris Cotter     Obj other{std::move(o1)};
256c491c917SChris Cotter   };
257c491c917SChris Cotter 
258c491c917SChris Cotter   auto not_rvalue_ref = [](Obj& o1) {
259c491c917SChris Cotter     Obj other{std::move(o1)};
260c491c917SChris Cotter   };
261c491c917SChris Cotter 
262c491c917SChris Cotter   Obj local;
263c491c917SChris Cotter   auto captures = [local]() { };
264c491c917SChris Cotter }
265c491c917SChris Cotter 
266c491c917SChris Cotter struct AClass {
member_with_lambda_no_moveAClass267c491c917SChris Cotter   void member_with_lambda_no_move(Obj&& o) {
268c491c917SChris Cotter     // CHECK-MESSAGES: :[[@LINE-1]]:41: warning: rvalue reference parameter 'o' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
269c491c917SChris Cotter     auto captures_this = [=, this]() {
270c491c917SChris Cotter       Obj other = std::move(o);
271c491c917SChris Cotter     };
272c491c917SChris Cotter   }
member_with_lambda_that_movesAClass273c491c917SChris Cotter   void member_with_lambda_that_moves(Obj&& o) {
274c491c917SChris Cotter     auto captures_this = [&, this]() {
275c491c917SChris Cotter       Obj other = std::move(o);
276c491c917SChris Cotter     };
277c491c917SChris Cotter   }
278c491c917SChris Cotter };
279c491c917SChris Cotter 
useless_move(Obj && o)280c491c917SChris Cotter void useless_move(Obj&& o) {
281c491c917SChris Cotter   // FIXME - The object is not actually moved from - this should probably be
282c491c917SChris Cotter   // flagged by *some* check. Which one?
283c491c917SChris Cotter   std::move(o);
284c491c917SChris Cotter }
285c491c917SChris Cotter 
286c491c917SChris Cotter template <typename>
287c491c917SChris Cotter class TemplatedClass;
288c491c917SChris Cotter 
289c491c917SChris Cotter template <typename T>
unresolved_lookup(TemplatedClass<T> && o)290c491c917SChris Cotter void unresolved_lookup(TemplatedClass<T>&& o) {
291c491c917SChris Cotter   TemplatedClass<T> moved = std::move(o);
292c491c917SChris Cotter }
293c491c917SChris Cotter 
294c491c917SChris Cotter struct DefinesMove {
DefinesMoveDefinesMove295c491c917SChris Cotter   DefinesMove(DefinesMove&& rhs) : o(std::move(rhs.o)) { }
operator =DefinesMove296c491c917SChris Cotter   DefinesMove& operator=(DefinesMove&& rhs) {
297c491c917SChris Cotter     if (this != &rhs) {
298c491c917SChris Cotter       o = std::move(rhs.o);
299c491c917SChris Cotter     }
300c491c917SChris Cotter     return *this;
301c491c917SChris Cotter   }
302c491c917SChris Cotter   Obj o;
303c491c917SChris Cotter };
304c491c917SChris Cotter 
305c491c917SChris Cotter struct DeclaresMove {
306c491c917SChris Cotter   DeclaresMove(DeclaresMove&& rhs);
307c491c917SChris Cotter   DeclaresMove& operator=(DeclaresMove&& rhs);
308c491c917SChris Cotter };
309c491c917SChris Cotter 
310c491c917SChris Cotter struct AnotherObj {
AnotherObjAnotherObj311c491c917SChris Cotter   AnotherObj(Obj&& o) : o(std::move(o)) {}
AnotherObjAnotherObj312c491c917SChris Cotter   AnotherObj(Obj&& o, int) { o = std::move(o); }
313c491c917SChris Cotter   Obj o;
314c491c917SChris Cotter };
315c491c917SChris Cotter 
316c491c917SChris Cotter template <class T>
317c491c917SChris Cotter struct AClassTemplate {
AClassTemplateAClassTemplate318c491c917SChris Cotter   AClassTemplate(T&& t) {}
319c491c917SChris Cotter   // CHECK-MESSAGES-NONDEDUCED: :[[@LINE-1]]:22: warning: rvalue reference parameter 't' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
320c491c917SChris Cotter 
movesAClassTemplate321c491c917SChris Cotter   void moves(T&& t) {
322c491c917SChris Cotter     T other = std::move(t);
323c491c917SChris Cotter   }
never_movesAClassTemplate324c491c917SChris Cotter   void never_moves(T&& t) {}
325c491c917SChris Cotter   // CHECK-MESSAGES-NONDEDUCED: :[[@LINE-1]]:24: warning: rvalue reference parameter 't' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
326c491c917SChris Cotter };
327c491c917SChris Cotter 
instantiate_a_class_template()328c491c917SChris Cotter void instantiate_a_class_template() {
329c491c917SChris Cotter   Obj o;
330c491c917SChris Cotter   AClassTemplate<Obj> withObj{std::move(o)};
331c491c917SChris Cotter   withObj.never_moves(std::move(o));
332c491c917SChris Cotter 
333c491c917SChris Cotter   AClassTemplate<Obj&> withObjRef(o);
334c491c917SChris Cotter   withObjRef.never_moves(o);
335c491c917SChris Cotter }
336bb6a98c8SAMS21 
337*20d21028SPiotr Zegar namespace gh68209 {
f1(int && x)338bb6a98c8SAMS21   void f1([[maybe_unused]] int&& x) {}
339bb6a98c8SAMS21 
f2(int && x)340bb6a98c8SAMS21   void f2(__attribute__((unused)) int&& x) {}
341bb6a98c8SAMS21 
f3(int && x)342bb6a98c8SAMS21   void f3(int&& x) {}
343bb6a98c8SAMS21   // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: rvalue reference parameter 'x' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
344bb6a98c8SAMS21 
345bb6a98c8SAMS21   template <typename T>
f4(T && x)346bb6a98c8SAMS21   void f4([[maybe_unused]] T&& x) {}
347bb6a98c8SAMS21 
348bb6a98c8SAMS21   template <typename T>
f5(__attribute ((unused))T && x)349bb6a98c8SAMS21   void f5(__attribute((unused)) T&& x) {}
350bb6a98c8SAMS21 
351bb6a98c8SAMS21   template<typename T>
f6(T && x)352bb6a98c8SAMS21   void f6(T&& x) {}
353bb6a98c8SAMS21 
f7(int && x)354bb6a98c8SAMS21   void f7([[maybe_unused]] int&& x) { x += 1; }
355bb6a98c8SAMS21   // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: rvalue reference parameter 'x' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
356bb6a98c8SAMS21 
f8(int && x)357bb6a98c8SAMS21   void f8(__attribute__((unused)) int&& x) { x += 1; }
358bb6a98c8SAMS21   // CHECK-MESSAGES: :[[@LINE-1]]:41: warning: rvalue reference parameter 'x' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
359bb6a98c8SAMS21 } // namespace gh68209
360*20d21028SPiotr Zegar 
361*20d21028SPiotr Zegar namespace gh69412 {
362*20d21028SPiotr Zegar   struct S
363*20d21028SPiotr Zegar   {
364*20d21028SPiotr Zegar       S(const int&);
365*20d21028SPiotr Zegar       S(int&&) = delete;
366*20d21028SPiotr Zegar 
367*20d21028SPiotr Zegar       void foo(int&&) = delete;
368*20d21028SPiotr Zegar   };
369*20d21028SPiotr Zegar } // namespace gh69412
370