bump product version to 6.4.0.3
[LibreOffice.git] / compilerplugins / clang / test / constvars.cxx
blobdc3c1ecb9c6bd048fa9a2de8ac2b5205cb774df8
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 #if defined _WIN32 //TODO, see corresponding TODO in compilerplugins/clang/writeonlyvars.cxx
11 // expected-no-diagnostics
12 #else
14 #include <com/sun/star/uno/Any.hxx>
15 #include <com/sun/star/uno/Sequence.hxx>
16 #include <com/sun/star/uno/XInterface.hpp>
17 #include <map>
18 #include <list>
19 #include <vector>
20 #include <rtl/ustring.hxx>
22 namespace test1
24 int const aFormalArgs[] = { 1, 2 };
25 // expected-error@+1 {{var can be const [loplugin:constvars]}}
26 static sal_uInt16 nMediaArgsCount = SAL_N_ELEMENTS(aFormalArgs);
27 sal_uInt16 foo()
29 (void)aFormalArgs;
30 return nMediaArgsCount;
34 // no warning expected
35 namespace test2
37 static char const* ar[] = { "xxxx" };
38 static const char* lcl_DATA_OTHERS = "localedata_others";
39 void foo()
41 (void)ar;
42 (void)lcl_DATA_OTHERS;
46 // no warning expected
47 namespace test3
49 static sal_uInt16 nMediaArgsCount = 1; // loplugin:constvars:ignore
50 sal_uInt16 foo() { return nMediaArgsCount; }
53 // no warning expected, we don't handle these destructuring assignments properly yet
54 namespace test4
56 void foo()
58 std::map<OUString, OUString> aMap;
59 for (auto & [ rName, rEntry ] : aMap)
61 rEntry.clear();
66 // no warning expected
67 namespace test5
69 struct Struct1
72 void release(Struct1*);
73 void foo(std::list<Struct1*> aList)
75 for (Struct1* pItem : aList)
77 release(pItem);
82 namespace test6
84 void foo(css::uno::Sequence<css::uno::Reference<css::uno::XInterface>>& aSeq)
86 // expected-error@+1 {{var can be const [loplugin:constvars]}}
87 for (css::uno::Reference<css::uno::XInterface>& x : aSeq)
89 x.get();
94 // no warning expected
95 namespace test7
97 void foo(std::vector<std::vector<int>> aVecVec)
99 for (auto& rVec : aVecVec)
100 for (auto& rElement : rVec)
101 rElement = 1;
105 #endif
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */