Lines Matching +full:- +full:a

1 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
2 // RUN: -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
3 // RUN: -analyzer-config exploration_strategy=unexplored_first_queue\
4 // RUN: -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
5 // RUN: -verify=expected,peaceful,non-aggressive
6 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
7 // RUN: -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
8 // RUN: -analyzer-config exploration_strategy=dfs -DDFS\
9 // RUN: -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
10 // RUN: -verify=expected,peaceful,non-aggressive
11 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
12 // RUN: -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
13 // RUN: -analyzer-config exploration_strategy=unexplored_first_queue\
14 // RUN: -analyzer-config cplusplus.Move:WarnOn=KnownsOnly\
15 // RUN: -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
16 // RUN: -verify=expected,non-aggressive
17 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move -verify %s\
18 // RUN: -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
19 // RUN: -analyzer-config exploration_strategy=dfs -DDFS\
20 // RUN: -analyzer-config cplusplus.Move:WarnOn=KnownsOnly\
21 // RUN: -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
22 // RUN: -verify=expected,non-aggressive
23 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
24 // RUN: -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
25 // RUN: -analyzer-config exploration_strategy=unexplored_first_queue\
26 // RUN: -analyzer-config cplusplus.Move:WarnOn=All\
27 // RUN: -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
28 // RUN: -verify=expected,peaceful,aggressive
29 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
30 // RUN: -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
31 // RUN: -analyzer-config exploration_strategy=dfs -DDFS\
32 // RUN: -analyzer-config cplusplus.Move:WarnOn=All\
33 // RUN: -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
34 // RUN: -verify=expected,peaceful,aggressive
36 // RUN: not %clang_analyze_cc1 -verify %s \
37 // RUN: -analyzer-checker=core \
38 // RUN: -analyzer-checker=cplusplus.Move \
39 // RUN: -analyzer-config cplusplus.Move:WarnOn="a bunch of things" \
40 // RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-MOVE-INVALID-VALUE
42 // CHECK-MOVE-INVALID-VALUE: (frontend): invalid input for checker option
43 // CHECK-MOVE-INVALID-VALUE-SAME: 'cplusplus.Move:WarnOn', that expects either
44 // CHECK-MOVE-INVALID-VALUE-SAME: "KnownsOnly", "KnownsAndLocals" or "All"
45 // CHECK-MOVE-INVALID-VALUE-SAME: string value
47 // Tests checker-messages printing.
48 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.Move %s\
49 // RUN: -std=c++11 -analyzer-output=text -analyzer-config eagerly-assume=false\
50 // RUN: -analyzer-config exploration_strategy=dfs -DDFS\
51 // RUN: -analyzer-config cplusplus.Move:WarnOn=All -DAGGRESSIVE_DFS\
52 // RUN: -analyzer-checker core,cplusplus.SmartPtrModeling,debug.ExprInspection\
53 // RUN: -verify=expected,peaceful,aggressive %s 2>&1 | FileCheck %s
55 #include "Inputs/system-header-simulator-cxx.h"
72 class A { class
78 A(int ii = 42, double dd = 1.0) : d(dd), i(ii), b(B()) {} in A() function in A
79 void moveconstruct(A &&other) { in moveconstruct()
85 static A get() { in get()
86 A v(12, 13); in get()
89 A(A *a) { in A() function in A
90 moveconstruct(std::move(*a)); in A()
92 A(const A &other) : i(other.i), d(other.d), b(other.b) {} in A() function in A
93A(A &&other) : i(other.i), d(other.d), b(std::move(other.b)) { // aggressive-note{{Object 'b' is m… in A() function in A
95 A(A &&other, char *k) { in A() function in A
98 void operator=(const A &other) { in operator =()
104 void operator=(A &&other) { in operator =()
115 void assign(const A &);
121 A a; in testUpdateField() local
122 A b = std::move(a); in testUpdateField()
123 a.i = 1; in testUpdateField()
124 a.foo(); // no-warning in testUpdateField()
127 A a; in testUpdateFieldDouble() local
128 A b = std::move(a); in testUpdateFieldDouble()
129 a.d = 1.0; in testUpdateFieldDouble()
130 a.foo(); // no-warning in testUpdateFieldDouble()
136 void moveInsideFunctionCall(A a) { in moveInsideFunctionCall() argument
137 A b = std::move(a); in moveInsideFunctionCall()
139 void leftRefCall(A &a) { in leftRefCall() argument
140 a.foo(); in leftRefCall()
142 void rightRefCall(A &&a) { in rightRefCall() argument
143 a.foo(); in rightRefCall()
145 void constCopyOrMoveCall(const A a) { in constCopyOrMoveCall() argument
146 a.foo(); in constCopyOrMoveCall()
149 void copyOrMoveCall(A a) { in copyOrMoveCall() argument
150 a.foo(); in copyOrMoveCall()
155 A a; in simpleMoveCtorTest() local
156 A b = std::move(a); // peaceful-note {{Object 'a' is moved}} in simpleMoveCtorTest()
162 // CHECK-NEXT: { "checker": "cplusplus.Move", "messages": [ in simpleMoveCtorTest()
163 // CHECK-NEXT: "Moved-from objects :", in simpleMoveCtorTest()
164 // CHECK: "a: moved", in simpleMoveCtorTest()
166 // CHECK-NEXT: ]} in simpleMoveCtorTest()
167 // CHECK-NEXT: ] in simpleMoveCtorTest()
170 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in simpleMoveCtorTest()
171 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in simpleMoveCtorTest()
174 A a; in simpleMoveCtorTest() local
175 A b = std::move(a); // peaceful-note {{Object 'a' is moved}} in simpleMoveCtorTest()
176 b = a; // peaceful-warning {{Moved-from object 'a' is copied}} in simpleMoveCtorTest()
177 // peaceful-note@-1 {{Moved-from object 'a' is copied}} in simpleMoveCtorTest()
180 A a; in simpleMoveCtorTest() local
181 A b = std::move(a); // peaceful-note {{Object 'a' is moved}} in simpleMoveCtorTest()
182 b = std::move(a); // peaceful-warning {{Moved-from object 'a' is moved}} in simpleMoveCtorTest()
183 // peaceful-note@-1 {{Moved-from object 'a' is moved}} in simpleMoveCtorTest()
189 A a; in simpleMoveAssignementTest() local
190 A b; in simpleMoveAssignementTest()
191 b = std::move(a); // peaceful-note {{Object 'a' is moved}} in simpleMoveAssignementTest()
192 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in simpleMoveAssignementTest()
193 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in simpleMoveAssignementTest()
196 A a; in simpleMoveAssignementTest() local
197 A b; in simpleMoveAssignementTest()
198 b = std::move(a); // peaceful-note {{Object 'a' is moved}} in simpleMoveAssignementTest()
199 A c(a); // peaceful-warning {{Moved-from object 'a' is copied}} in simpleMoveAssignementTest()
200 // peaceful-note@-1 {{Moved-from object 'a' is copied}} in simpleMoveAssignementTest()
203 A a; in simpleMoveAssignementTest() local
204 A b; in simpleMoveAssignementTest()
205 b = std::move(a); // peaceful-note {{Object 'a' is moved}} in simpleMoveAssignementTest()
206 A c(std::move(a)); // peaceful-warning {{Moved-from object 'a' is moved}} in simpleMoveAssignementTest()
207 // peaceful-note@-1 {{Moved-from object 'a' is moved}} in simpleMoveAssignementTest()
213 A a; in moveInInitListTest() member
215 A a; in moveInInitListTest() local
216 S s{std::move(a)}; // peaceful-note {{Object 'a' is moved}} in moveInInitListTest()
217 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in moveInInitListTest()
218 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in moveInInitListTest()
221 // Don't report a bug if the variable was assigned to in the meantime.
224 A a; in reinitializationTest() local
225 A b; in reinitializationTest()
226 b = std::move(a); in reinitializationTest()
227 a = A(); in reinitializationTest()
228 a.foo(); in reinitializationTest()
231 A a; in reinitializationTest() local
232 if (i == 1) { // peaceful-note 2 {{Assuming 'i' is not equal to 1}} in reinitializationTest()
233 // peaceful-note@-1 2 {{Taking false branch}} in reinitializationTest()
234 A b; in reinitializationTest()
235 b = std::move(a); in reinitializationTest()
236 a = A(); in reinitializationTest()
238 if (i == 2) { // peaceful-note 2 {{Assuming 'i' is not equal to 2}} in reinitializationTest()
239 // peaceful-note@-1 2 {{Taking false branch}} in reinitializationTest()
240 a.foo(); // no-warning in reinitializationTest()
244 A a; in reinitializationTest() local
245 if (i == 1) { // peaceful-note 2 {{'i' is not equal to 1}} in reinitializationTest()
246 // peaceful-note@-1 2 {{Taking false branch}} in reinitializationTest()
247 std::move(a); in reinitializationTest()
249 if (i == 2) { // peaceful-note 2 {{'i' is not equal to 2}} in reinitializationTest()
250 // peaceful-note@-1 2 {{Taking false branch}} in reinitializationTest()
251 a = A(); in reinitializationTest()
252 a.foo(); in reinitializationTest()
255 // The built-in assignment operator should also be recognized as a in reinitializationTest()
256 // reinitialization. (std::move() may be called on built-in types in template in reinitializationTest()
262 // A std::move() after the assignment makes the variable invalid again. in reinitializationTest()
264 A a; in reinitializationTest() local
265 A b; in reinitializationTest()
266 b = std::move(a); in reinitializationTest()
267 a = A(); in reinitializationTest()
268 b = std::move(a); // peaceful-note {{Object 'a' is moved}} in reinitializationTest()
269 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in reinitializationTest()
270 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in reinitializationTest()
272 // If a path exist where we not reinitialize the variable we report a bug. in reinitializationTest()
274 A a; in reinitializationTest() local
275 A b; in reinitializationTest()
276 b = std::move(a); // peaceful-note {{Object 'a' is moved}} in reinitializationTest()
277 if (i < 10) { // peaceful-note {{Assuming 'i' is >= 10}} in reinitializationTest()
278 // peaceful-note@-1 {{Taking false branch}} in reinitializationTest()
279 a = A(); in reinitializationTest()
281 if (i > 5) { // peaceful-note {{'i' is > 5}} in reinitializationTest()
282 // peaceful-note@-1 {{Taking true branch}} in reinitializationTest()
283 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in reinitializationTest()
284 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in reinitializationTest()
289 // Using decltype on an expression is not a use.
291 A a; in decltypeIsNotUseTest() local
292 // A b(std::move(a)); in decltypeIsNotUseTest()
293 decltype(a) other_a; // no-warning in decltypeIsNotUseTest()
298 A a; in loopTest() local
300 …for (int i = 0; i < bignum(); i++) { // peaceful-note {{Loop condition is false. Execution jumps t… in loopTest()
301 rightRefCall(std::move(a)); // no-warning in loopTest()
305 A a; in loopTest() local
306 … for (int i = 0; i < 2; i++) { // peaceful-note {{Loop condition is true. Entering loop body}} in loopTest()
307 … // peaceful-note@-1 {{Loop condition is true. Entering loop body}} in loopTest()
308 … // peaceful-note@-2 {{Loop condition is false. Execution jumps to the end of the function}} in loopTest()
309 rightRefCall(std::move(a)); // no-warning in loopTest()
313 A a; in loopTest() local
314 …for (int i = 0; i < bignum(); i++) { // peaceful-note {{Loop condition is false. Execution jumps t… in loopTest()
315 leftRefCall(a); // no-warning in loopTest()
319 A a; in loopTest() local
320 … for (int i = 0; i < 2; i++) { // peaceful-note {{Loop condition is true. Entering loop body}} in loopTest()
321 … // peaceful-note@-1 {{Loop condition is true. Entering loop body}} in loopTest()
322 … // peaceful-note@-2 {{Loop condition is false. Execution jumps to the end of the function}} in loopTest()
323 leftRefCall(a); // no-warning in loopTest()
327 A a; in loopTest() local
328 …for (int i = 0; i < bignum(); i++) { // peaceful-note {{Loop condition is false. Execution jumps t… in loopTest()
329 constCopyOrMoveCall(a); // no-warning in loopTest()
333 A a; in loopTest() local
334 … for (int i = 0; i < 2; i++) { // peaceful-note {{Loop condition is true. Entering loop body}} in loopTest()
335 … // peaceful-note@-1 {{Loop condition is true. Entering loop body}} in loopTest()
336 … // peaceful-note@-2 {{Loop condition is false. Execution jumps to the end of the function}} in loopTest()
337 constCopyOrMoveCall(a); // no-warning in loopTest()
341 A a; in loopTest() local
342 …for (int i = 0; i < bignum(); i++) { // peaceful-note {{Loop condition is false. Execution jumps t… in loopTest()
343 moveInsideFunctionCall(a); // no-warning in loopTest()
347 A a; in loopTest() local
348 … for (int i = 0; i < 2; i++) { // peaceful-note {{Loop condition is true. Entering loop body}} in loopTest()
349 … // peaceful-note@-1 {{Loop condition is true. Entering loop body}} in loopTest()
350 … // peaceful-note@-2 {{Loop condition is false. Execution jumps to the end of the function}} in loopTest()
351 moveInsideFunctionCall(a); // no-warning in loopTest()
355 A a; in loopTest() local
356 …for (int i = 0; i < bignum(); i++) { // peaceful-note {{Loop condition is false. Execution jumps t… in loopTest()
357 copyOrMoveCall(a); // no-warning in loopTest()
361 A a; in loopTest() local
362 … for (int i = 0; i < 2; i++) { // peaceful-note {{Loop condition is true. Entering loop body}} in loopTest()
363 … // peaceful-note@-1 {{Loop condition is true. Entering loop body}} in loopTest()
364 … // peaceful-note@-2 {{Loop condition is false. Execution jumps to the end of the function}} in loopTest()
365 copyOrMoveCall(a); // no-warning in loopTest()
369 A a; in loopTest() local
370 …for (int i = 0; i < bignum(); i++) { // peaceful-note {{Loop condition is true. Entering loop … in loopTest()
371 … // peaceful-note@-1 {{Loop condition is true. Entering loop body}} in loopTest()
372 constCopyOrMoveCall(std::move(a)); // peaceful-note {{Object 'a' is moved}} in loopTest()
373 // peaceful-warning@-1 {{Moved-from object 'a' is moved}} in loopTest()
374 // peaceful-note@-2 {{Moved-from object 'a' is moved}} in loopTest()
380 A a; in loopTest() local
382 a.bar(); in loopTest()
383 if (a.foo() > 0) { in loopTest()
384 A b; in loopTest()
385 b = std::move(a); // no-warning in loopTest()
392 // Report a usage of a moved-from object only at the first use.
394 A a(42, 42.0); in uniqueTest() local
395 A b; in uniqueTest()
396 b = std::move(a); // peaceful-note {{Object 'a' is moved}} in uniqueTest()
398 if (cond) { // peaceful-note {{Assuming 'cond' is true}} in uniqueTest()
399 // peaceful-note@-1 {{Taking true branch}} in uniqueTest()
400 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in uniqueTest()
401 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in uniqueTest()
404 a.bar(); // no-warning in uniqueTest()
407 a.bar(); // no-warning in uniqueTest()
411 A a; in uniqueTest2() local
412 A a1 = std::move(a); // peaceful-note {{Object 'a' is moved}} in uniqueTest2()
413 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in uniqueTest2()
414 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in uniqueTest2()
416 A a2 = std::move(a); // no-warning in uniqueTest2()
417 a.foo(); // no-warning in uniqueTest2()
421 //even on moved-from objects.
423 A a; in moveSafeFunctionsTest() local
424 A b = std::move(a); // peaceful-note {{Object 'a' is moved}} in moveSafeFunctionsTest()
425 a.empty(); // no-warning in moveSafeFunctionsTest()
426 a.isEmpty(); // no-warning in moveSafeFunctionsTest()
427 (void)a; // no-warning in moveSafeFunctionsTest()
428 (bool)a; // expected-warning {{expression result unused}} in moveSafeFunctionsTest()
429 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in moveSafeFunctionsTest()
430 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in moveSafeFunctionsTest()
435 A a; in moveStateResetFunctionsTest() local
436 A b = std::move(a); in moveStateResetFunctionsTest()
437 a.reset(); // no-warning in moveStateResetFunctionsTest()
438 a.foo(); // no-warning in moveStateResetFunctionsTest()
440 a.b.foo(); // no-warning in moveStateResetFunctionsTest()
443 A a; in moveStateResetFunctionsTest() local
444 A b = std::move(a); in moveStateResetFunctionsTest()
445 a.destroy(); // no-warning in moveStateResetFunctionsTest()
446 a.foo(); // no-warning in moveStateResetFunctionsTest()
449 A a; in moveStateResetFunctionsTest() local
450 A b = std::move(a); in moveStateResetFunctionsTest()
451 a.clear(); // no-warning in moveStateResetFunctionsTest()
452 a.foo(); // no-warning in moveStateResetFunctionsTest()
453 a.b.foo(); // no-warning in moveStateResetFunctionsTest()
456 A a; in moveStateResetFunctionsTest() local
457 A b = std::move(a); in moveStateResetFunctionsTest()
458 a.resize(0); // no-warning in moveStateResetFunctionsTest()
459 a.foo(); // no-warning in moveStateResetFunctionsTest()
460 a.b.foo(); // no-warning in moveStateResetFunctionsTest()
463 A a; in moveStateResetFunctionsTest() local
464 A b = std::move(a); in moveStateResetFunctionsTest()
465 a.assign(A()); // no-warning in moveStateResetFunctionsTest()
466 a.foo(); // no-warning in moveStateResetFunctionsTest()
467 a.b.foo(); // no-warning in moveStateResetFunctionsTest()
475 void foo(A a);
479 void functionTemplate(A a);
483 // A pattern like this occurs in the EXPECT_EQ and ASSERT_EQ macros in in templateArgIsNotUseTest()
485 A a; in templateArgIsNotUseTest() local
486 ClassTemplate<sizeof(A(std::move(a)))>().foo(std::move(a)); // no-warning in templateArgIsNotUseTest()
489 A a; in templateArgIsNotUseTest() local
490 functionTemplate<sizeof(A(std::move(a)))>(std::move(a)); // no-warning in templateArgIsNotUseTest()
495 A global_a;
498 global_a.foo(); // no-warning in globalVariablesTest()
503 A a; member in memberVariablesTest
504 static A static_a;
507 A b; in f()
508 b = std::move(a); // aggressive-note {{Object 'a' is moved}} in f()
510 a.foo(); // aggressive-warning {{Method called on moved-from object 'a'}} in f()
511 // aggressive-note@-1 {{Method called on moved-from object 'a'}} in f()
513 b = std::move(static_a); // aggressive-note {{Object 'static_a' is moved}} in f()
514 static_a.foo(); // aggressive-warning {{Method called on moved-from object 'static_a'}} in f()
515 // aggressive-note@-1 {{Method called on moved-from object 'static_a'}} in f()
520 A *Ptr = new A(1, 1.5); in PtrAndArrayTest()
521 A Arr[10]; in PtrAndArrayTest()
522 Arr[2] = std::move(*Ptr); // aggressive-note{{Object is moved}} in PtrAndArrayTest()
523 (*Ptr).foo(); // aggressive-warning{{Method called on moved-from object}} in PtrAndArrayTest()
524 // aggressive-note@-1{{Method called on moved-from object}} in PtrAndArrayTest()
527 Arr[3] = std::move(Arr[1]); // aggressive-note {{Object is moved}} in PtrAndArrayTest()
528 Ptr->foo(); // aggressive-warning {{Method called on moved-from object}} in PtrAndArrayTest()
529 // aggressive-note@-1 {{Method called on moved-from object}} in PtrAndArrayTest()
531 Arr[3] = std::move(Arr[2]); // aggressive-note{{Object is moved}} in PtrAndArrayTest()
532 Arr[2].foo(); // aggressive-warning{{Method called on moved-from object}} in PtrAndArrayTest()
533 // aggressive-note@-1{{Method called on moved-from object}} in PtrAndArrayTest()
536 Arr[2].foo(); // no-warning in PtrAndArrayTest()
540 A a; in exclusiveConditionsTest() local
542 A b; in exclusiveConditionsTest()
543 b = std::move(a); in exclusiveConditionsTest()
546 a.bar(); // no-warning in exclusiveConditionsTest()
551 // Don't warn if the use is in a different branch from the move. in differentBranchesTest()
553 A a; in differentBranchesTest() local
554 if (i > 0) { // peaceful-note {{Assuming 'i' is > 0}} in differentBranchesTest()
555 // peaceful-note@-1 {{Taking true branch}} in differentBranchesTest()
556 A b; in differentBranchesTest()
557 b = std::move(a); in differentBranchesTest()
559 a.foo(); // no-warning in differentBranchesTest()
562 // Same thing, but with a ternary operator. in differentBranchesTest()
564 A a, b; in differentBranchesTest() local
565 i > 0 ? (void)(b = std::move(a)) : a.bar(); // no-warning in differentBranchesTest()
566 // peaceful-note@-1 {{'i' is > 0}} in differentBranchesTest()
567 // peaceful-note@-2 {{'?' condition is true}} in differentBranchesTest()
569 // A variation on the theme above. in differentBranchesTest()
571 A a; in differentBranchesTest() local
572 a.foo() > 0 ? a.foo() : A(std::move(a)).foo(); in differentBranchesTest()
574 // peaceful-note@-2 {{Assuming the condition is false}} in differentBranchesTest()
575 // peaceful-note@-3 {{'?' condition is false}} in differentBranchesTest()
577 // peaceful-note@-5 {{Assuming the condition is true}} in differentBranchesTest()
578 // peaceful-note@-6 {{'?' condition is true}} in differentBranchesTest()
581 // Same thing, but with a switch statement. in differentBranchesTest()
583 A a, b; in differentBranchesTest() local
584 switch (i) { // peaceful-note {{Control jumps to 'case 1:'}} in differentBranchesTest()
586 b = std::move(a); // no-warning in differentBranchesTest()
588 break; // peaceful-note {{Execution jumps to the end of the function}} in differentBranchesTest()
590 a.foo(); // no-warning in differentBranchesTest()
594 // However, if there's a fallthrough, we do warn. in differentBranchesTest()
596 A a, b; in differentBranchesTest() local
597 switch (i) { // peaceful-note {{Control jumps to 'case 1:'}} in differentBranchesTest()
599 b = std::move(a); // peaceful-note {{Object 'a' is moved}} in differentBranchesTest()
601 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in differentBranchesTest()
602 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in differentBranchesTest()
609 A a = A::get(); in tempTest() local
610 A::get().foo(); // no-warning in tempTest()
612 A::get().foo(); // no-warning in tempTest()
616 void interFunTest1(A &a) { in interFunTest1() argument
617 a.bar(); // peaceful-warning {{Method called on moved-from object 'a'}} in interFunTest1()
618 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in interFunTest1()
622 A a; in interFunTest2() local
623 A b; in interFunTest2()
624 b = std::move(a); // peaceful-note {{Object 'a' is moved}} in interFunTest2()
625 interFunTest1(a); // peaceful-note {{Calling 'interFunTest1'}} in interFunTest2()
628 void foobar(A a, int i);
629 void foobar(int i, A a);
632 A a; in paramEvaluateOrderTest() local
633 foobar(std::move(a), a.getI()); // peaceful-note {{Object 'a' is moved}} in paramEvaluateOrderTest()
634 // peaceful-warning@-1 {{Method called on moved-from object 'a'}} in paramEvaluateOrderTest()
635 // peaceful-note@-2 {{Method called on moved-from object 'a'}} in paramEvaluateOrderTest()
638 foobar(a.getI(), std::move(a)); //no-warning in paramEvaluateOrderTest()
641 void not_known_pass_by_ref(A &a);
642 void not_known_pass_by_const_ref(const A &a);
643 void not_known_pass_by_rvalue_ref(A &&a);
644 void not_known_pass_by_ptr(A *a);
645 void not_known_pass_by_const_ptr(const A *a);
649 A a; in regionAndPointerEscapeTest() local
650 A b; in regionAndPointerEscapeTest()
651 b = std::move(a); in regionAndPointerEscapeTest()
652 not_known_pass_by_ref(a); in regionAndPointerEscapeTest()
653 a.foo(); // no-warning in regionAndPointerEscapeTest()
656 A a; in regionAndPointerEscapeTest() local
657 A b; in regionAndPointerEscapeTest()
658 b = std::move(a); // peaceful-note{{Object 'a' is moved}} in regionAndPointerEscapeTest()
659 not_known_pass_by_const_ref(a); in regionAndPointerEscapeTest()
660 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in regionAndPointerEscapeTest()
661 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in regionAndPointerEscapeTest()
664 A a; in regionAndPointerEscapeTest() local
665 A b; in regionAndPointerEscapeTest()
666 b = std::move(a); in regionAndPointerEscapeTest()
667 not_known_pass_by_rvalue_ref(std::move(a)); in regionAndPointerEscapeTest()
668 a.foo(); // no-warning in regionAndPointerEscapeTest()
671 A a; in regionAndPointerEscapeTest() local
672 A b; in regionAndPointerEscapeTest()
673 b = std::move(a); in regionAndPointerEscapeTest()
674 not_known_pass_by_ptr(&a); in regionAndPointerEscapeTest()
675 a.foo(); // no-warning in regionAndPointerEscapeTest()
678 A a; in regionAndPointerEscapeTest() local
679 A b; in regionAndPointerEscapeTest()
680 b = std::move(a); // peaceful-note {{Object 'a' is moved}} in regionAndPointerEscapeTest()
681 not_known_pass_by_const_ptr(&a); in regionAndPointerEscapeTest()
682 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in regionAndPointerEscapeTest()
683 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in regionAndPointerEscapeTest()
687 // A declaration statement containing multiple declarations sequences the
691 A a; in declarationSequenceTest() local
692 A a1 = a, a2 = std::move(a); // no-warning in declarationSequenceTest()
695 A a; in declarationSequenceTest() local
696 A a1 = std::move(a), a2 = a; // peaceful-note {{Object 'a' is moved}} in declarationSequenceTest()
697 // peaceful-warning@-1 {{Moved-from object 'a' is copied}} in declarationSequenceTest()
698 // peaceful-note@-2 {{Moved-from object 'a' is copied}} in declarationSequenceTest()
705 A a; in logicalOperatorsSequenceTest() local
706 …if (a.foo() > 0 && A(std::move(a)).foo() > 0) { // peaceful-note {{Assuming the condition is fa… in logicalOperatorsSequenceTest()
707 … // peaceful-note@-1 {{Left side of '&&' is false}} in logicalOperatorsSequenceTest()
708 // peaceful-note@-2 {{Taking false branch}} in logicalOperatorsSequenceTest()
710 … // peaceful-note@-4 {{Assuming the condition is false}} in logicalOperatorsSequenceTest()
711 … // peaceful-note@-5 {{Left side of '&&' is false}} in logicalOperatorsSequenceTest()
712 // peaceful-note@-6 {{Taking false branch}} in logicalOperatorsSequenceTest()
713 A().bar(); in logicalOperatorsSequenceTest()
716 // A variation: Negate the result of the && (which pushes the && further down in logicalOperatorsSequenceTest()
719 A a; in logicalOperatorsSequenceTest() local
720 …if (!(a.foo() > 0 && A(std::move(a)).foo() > 0)) { // peaceful-note {{Assuming the condition is… in logicalOperatorsSequenceTest()
721 … // peaceful-note@-1 {{Left side of '&&' is false}} in logicalOperatorsSequenceTest()
722 // peaceful-note@-2 {{Taking true branch}} in logicalOperatorsSequenceTest()
724 … // peaceful-note@-4 {{Assuming the condition is false}} in logicalOperatorsSequenceTest()
725 … // peaceful-note@-5 {{Left side of '&&' is false}} in logicalOperatorsSequenceTest()
726 // peaceful-note@-6 {{Taking true branch}} in logicalOperatorsSequenceTest()
727 A().bar(); in logicalOperatorsSequenceTest()
731 A a; in logicalOperatorsSequenceTest() local
732 if (A(std::move(a)).foo() > 0 && a.foo() > 0) { // peaceful-note {{Object 'a' is moved}} in logicalOperatorsSequenceTest()
733 … // peaceful-note@-1 {{Assuming the condition is true}} in logicalOperatorsSequenceTest()
734 … // peaceful-note@-2 {{Left side of '&&' is true}} in logicalOperatorsSequenceTest()
735 … // peaceful-warning@-3 {{Method called on moved-from object 'a'}} in logicalOperatorsSequenceTest()
736 … // peaceful-note@-4 {{Method called on moved-from object 'a'}} in logicalOperatorsSequenceTest()
738 … // peaceful-note@-6 {{Assuming the condition is false}} in logicalOperatorsSequenceTest()
739 … // peaceful-note@-7 {{Left side of '&&' is false}} in logicalOperatorsSequenceTest()
740 // peaceful-note@-8 {{Taking false branch}} in logicalOperatorsSequenceTest()
741 A().bar(); in logicalOperatorsSequenceTest()
745 A a; in logicalOperatorsSequenceTest() local
746 …if (a.foo() > 0 || A(std::move(a)).foo() > 0) { // peaceful-note {{Assuming the condition is tr… in logicalOperatorsSequenceTest()
747 … // peaceful-note@-1 {{Left side of '||' is true}} in logicalOperatorsSequenceTest()
748 // peaceful-note@-2 {{Taking true branch}} in logicalOperatorsSequenceTest()
749 A().bar(); in logicalOperatorsSequenceTest()
753 A a; in logicalOperatorsSequenceTest() local
754 if (A(std::move(a)).foo() > 0 || a.foo() > 0) { // peaceful-note {{Object 'a' is moved}} in logicalOperatorsSequenceTest()
755 … // peaceful-note@-1 {{Assuming the condition is false}} in logicalOperatorsSequenceTest()
756 … // peaceful-note@-2 {{Left side of '||' is false}} in logicalOperatorsSequenceTest()
757 … // peaceful-warning@-3 {{Method called on moved-from object 'a'}} in logicalOperatorsSequenceTest()
758 … // peaceful-note@-4 {{Method called on moved-from object 'a'}} in logicalOperatorsSequenceTest()
759 A().bar(); in logicalOperatorsSequenceTest()
764 // A range-based for sequences the loop variable declaration before the body.
766 A v[2] = {A(), A()}; in forRangeSequencesTest()
767 for (A &a : v) { in forRangeSequencesTest()
768 A b; in forRangeSequencesTest()
769 b = std::move(a); // no-warning in forRangeSequencesTest()
773 // If a variable is declared in an if statement, the declaration of the variable
774 // (which is treated like a reinitialization by the check) is sequenced before
775 // the evaluation of the condition (which constitutes a use).
778 if (A a = A()) { in ifStmtSequencesDeclAndConditionTest() local
779 A b; in ifStmtSequencesDeclAndConditionTest()
780 b = std::move(a); // no-warning in ifStmtSequencesDeclAndConditionTest()
785 struct C : public A {
791 A a; in subRegionMoveTest() local
792 B b = std::move(a.b); // aggressive-note {{Object 'b' is moved}} in subRegionMoveTest()
793 a.b.foo(); // aggressive-warning {{Method called on moved-from object 'b'}} in subRegionMoveTest()
794 // aggressive-note@-1 {{Method called on moved-from object 'b'}} in subRegionMoveTest()
797 A a; in subRegionMoveTest() local
798 A a1 = std::move(a); // aggressive-note {{Calling move constructor for 'A'}} in subRegionMoveTest()
799 // aggressive-note@-1 {{Returning from move constructor for 'A'}} in subRegionMoveTest()
800 a.b.foo(); // aggressive-warning{{Method called on moved-from object 'b'}} in subRegionMoveTest()
801 // aggressive-note@-1{{Method called on moved-from object 'b'}} in subRegionMoveTest()
803 // Don't report a misuse if any SuperRegion is already reported. in subRegionMoveTest()
805 A a; in subRegionMoveTest() local
806 A a1 = std::move(a); // peaceful-note {{Object 'a' is moved}} in subRegionMoveTest()
807 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in subRegionMoveTest()
808 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in subRegionMoveTest()
809 a.b.foo(); // no-warning in subRegionMoveTest()
813 C c1 = std::move(c); // peaceful-note {{Object 'c' is moved}} in subRegionMoveTest()
814 c.foo(); // peaceful-warning {{Method called on moved-from object 'c'}} in subRegionMoveTest()
815 // peaceful-note@-1 {{Method called on moved-from object 'c'}} in subRegionMoveTest()
816 c.b.foo(); // no-warning in subRegionMoveTest()
824 C c2 = c; // no-warning in resetSuperClass()
831 C c2 = c; // no-warning in resetSuperClass2()
836 C c1 = std::move(c); // peaceful-note {{Object 'c' is moved}} in reportSuperClass()
837 c.foo(); // peaceful-warning {{Method called on moved-from object 'c'}} in reportSuperClass()
838 // peaceful-note@-1 {{Method called on moved-from object 'c'}} in reportSuperClass()
839 C c2 = c; // no-warning in reportSuperClass()
849 return e; // no-warning in inlinedCall()
860 Empty f = std::move(e); // no-warning in checkLoopZombies()
868 e; // expected-warning {{expression result unused}} in checkMoreLoopZombies1()
869 Empty f = std::move(e); // no-warning in checkMoreLoopZombies1()
879 e; // expected-warning {{expression result unused}} in checkMoreLoopZombies2()
880 Empty f = std::move(e); // no-warning in checkMoreLoopZombies2()
888 e; // expected-warning {{expression result unused}} in checkMoreLoopZombies3()
890 Empty f = std::move(e); // no-warning in checkMoreLoopZombies3()
898 e; // expected-warning {{expression result unused}} in checkMoreLoopZombies4()
899 Empty f = std::move(e); // no-warning in checkMoreLoopZombies4()
918 // Warn even in non-aggressive mode when it comes to STL, because in testVector()
920 …std::vector<int> W = std::move(V); // expected-note {{Object 'V' of type 'std::vector' is left in in testVector()
921 V.push_back(123); // expected-warning {{Method called on moved-from object 'V'}} in testVector()
922 // expected-note@-1 {{Method called on moved-from object 'V'}} in testVector()
927 // unique_ptr remains in a well-defined state after move. in testUniquePtr()
928 std::unique_ptr<int> Q = std::move(P); // aggressive-note {{Object 'P' is moved}} in testUniquePtr()
929 …// non-aggressive-note@-1 {{Smart pointer 'P' of type 'std::unique_ptr' is reset to null when move… in testUniquePtr()
930 P.get(); // aggressive-warning{{Method called on moved-from object 'P'}} in testUniquePtr()
931 // aggressive-note@-1{{Method called on moved-from object 'P'}} in testUniquePtr()
933 // Because that well-defined state is null, dereference is still UB. in testUniquePtr()
936 …*P += 1; // non-aggressive-warning{{Dereference of null smart pointer 'P' of type 'std::unique_ptr… in testUniquePtr()
937 … // non-aggressive-note@-1{{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}} in testUniquePtr()
940 clang_analyzer_warnIfReached(); // no-warning in testUniquePtr()
944 void localRValueMove(A &&a) { in localRValueMove() argument
945 A b = std::move(a); // peaceful-note {{Object 'a' is moved}} in localRValueMove()
946 a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} in localRValueMove()
947 // peaceful-note@-1 {{Method called on moved-from object 'a'}} in localRValueMove()
952 // reusing a local variable this way usually indicates a bug. in localUniquePtr()
953 std::unique_ptr<int> Q = std::move(P); // peaceful-note {{Object 'P' is moved}} in localUniquePtr()
954 P.get(); // peaceful-warning {{Method called on moved-from object 'P'}} in localUniquePtr()
955 // peaceful-note@-1 {{Method called on moved-from object 'P'}} in localUniquePtr()
958 void localUniquePtrWithArrow(std::unique_ptr<A> P) { in localUniquePtrWithArrow()
959 …std::unique_ptr<A> Q = std::move(P); // expected-note{{Smart pointer 'P' of type 'std::unique_ptr'… in localUniquePtrWithArrow()
960 P->foo(); // expected-warning{{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}} in localUniquePtrWithArrow()
961 // expected-note@-1{{Dereference of null smart pointer 'P' of type 'std::unique_ptr'}} in localUniquePtrWithArrow()
964 void getAfterMove(std::unique_ptr<A> P) { in getAfterMove()
965 std::unique_ptr<A> Q = std::move(P); // peaceful-note {{Object 'P' is moved}} in getAfterMove()
968 if (P) // peaceful-note{{Taking false branch}} in getAfterMove()
969 clang_analyzer_warnIfReached(); // no-warning in getAfterMove()
971 A *a = P.get(); // peaceful-warning {{Method called on moved-from object 'P'}} in getAfterMove() local
972 // peaceful-note@-1 {{Method called on moved-from object 'P'}} in getAfterMove()
974 // TODO: Warn on a null dereference here. in getAfterMove()
975 a->foo(); in getAfterMove()
982 // Test the suppression caused by use-after-move semantics of in test()
987 // aggressive-note@-1 {{Object 'Task' is moved}} in test()
989 // aggressive-warning@-1{{Moved-from object 'Task' is moved}} in test()
990 // aggressive-note@-2 {{Moved-from object 'Task' is moved}} in test()