Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / compilerplugins / clang / test / moveit.cxx
blob9e4fa4f3d8147656cba17694514dd5ebba9c8710
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "config_clang.h"
11 #include <memory>
13 // expected-note@+3 {{type declared here [loplugin:moveit]}}
14 // expected-note@+2 {{type declared here [loplugin:moveit]}}
15 // expected-note@+1 {{type declared here [loplugin:moveit]}}
16 struct Movable
18 std::shared_ptr<int> x;
20 void method1();
22 Movable();
23 Movable(int);
26 namespace test1a
28 struct F
30 // expected-note@+1 {{passing to this param [loplugin:moveit]}}
31 void call_by_value(Movable);
32 void foo()
34 // expected-note@+1 {{local var declared here [loplugin:moveit]}}
35 Movable m;
36 // expected-error@+1 {{can std::move this var into this param [loplugin:moveit]}}
37 call_by_value(m);
42 namespace test1b
44 struct F
46 // expected-note@+1 {{passing to this param [loplugin:moveit]}}
47 F(Movable);
48 void foo()
50 // expected-note@+1 {{local var declared here [loplugin:moveit]}}
51 Movable m;
52 // expected-error@+1 {{can std::move this var into this param [loplugin:moveit]}}
53 F a(m);
54 (void)a;
59 namespace test2
61 struct F
63 // expected-note@+1 {{passing to this param [loplugin:moveit]}}
64 F(Movable);
65 void foo()
67 // expected-note@+1 {{local var declared here [loplugin:moveit]}}
68 Movable m;
69 // expected-error@+1 {{can std::move this var into this param [loplugin:moveit]}}
70 F a(m);
71 (void)a;
76 // No error expected, because referencing after call
77 namespace test3
79 struct F
81 F(Movable);
82 void foo()
84 Movable m;
85 F a(m);
86 m.method1();
91 // No error expected, because constructing temporary(i.e. rvalue) to pass to param
92 namespace test4
94 struct F
96 F(Movable);
97 void foo()
99 F a((Movable(5)));
100 (void)a;
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */