Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / compilerplugins / clang / test / oncevar.cxx
blobc8cc7bc1390d4b80682239aeabfae0f8473c830f
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 <rtl/ustring.hxx>
12 /*int foo() { return 1; }*/
14 void call_value(int);
15 void call_const_ref(int const &);
16 void call_ref(int &);
17 void call_value(OUString);
18 void call_const_ref(OUString const &);
19 void call_ref(OUString &);
21 template<typename T> void f() {
22 int i = sizeof (T) + 1; // expected-error {{var used only once, should be inlined or declared const [loplugin:oncevar]}}
23 call_value(i); // expected-note {{used here [loplugin:oncevar]}}
25 template void f<int>(); // needed for clang-cl
27 class Foo;
28 void method1(const Foo**);
30 int main() {
31 /* TODO
32 int i;
33 int x = 2;
34 if ( (i = foo()) == 0 ) {
35 x = 1;
40 int i1 = 2; // expected-error {{var used only once, should be inlined or declared const [loplugin:oncevar]}}
41 call_value(i1); // expected-note {{used here [loplugin:oncevar]}}
42 int i2 = 2; // expected-error {{var used only once, should be inlined or declared const [loplugin:oncevar]}}
43 call_const_ref(i2); // expected-note {{used here [loplugin:oncevar]}}
45 // don't expect warnings here
46 int i3;
47 call_ref(i3);
48 int const i4 = 2;
49 call_value(i4);
51 OUString s1("xxx"); // expected-error {{var used only once, should be inlined or declared const [loplugin:oncevar]}}
52 call_value(s1); // expected-note {{used here [loplugin:oncevar]}}
53 OUString s2("xxx"); // expected-error {{var used only once, should be inlined or declared const [loplugin:oncevar]}}
54 call_const_ref(s2); // expected-note {{used here [loplugin:oncevar]}}
56 // don't expect warnings here
57 OUString s3;
58 call_ref(s3);
59 OUString const s4("xxx");
60 call_value(s4);
62 const Foo* pInternalArgs[] = { nullptr };
63 method1(pInternalArgs);
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */