Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / compilerplugins / clang / test / constvars.cxx
blob88df50f8e199b4e63bf8beea8c73252486ba9a55
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/XInterface.hpp>
16 #include <map>
17 #include <list>
18 #include <vector>
19 #include <rtl/ustring.hxx>
21 namespace test1
23 int const aFormalArgs[] = { 1, 2 };
24 // expected-error@+1 {{var can be const [loplugin:constvars]}}
25 static sal_uInt16 nMediaArgsCount = SAL_N_ELEMENTS(aFormalArgs);
26 sal_uInt16 foo()
28 (void)aFormalArgs;
29 return nMediaArgsCount;
33 // no warning expected
34 namespace test2
36 static char const* ar[] = { "xxxx" };
37 static const char* lcl_DATA_OTHERS = "localedata_others";
38 void foo()
40 (void)ar;
41 (void)lcl_DATA_OTHERS;
45 // no warning expected
46 namespace test3
48 static sal_uInt16 nMediaArgsCount = 1; // loplugin:constvars:ignore
49 sal_uInt16 foo() { return nMediaArgsCount; }
52 // no warning expected, we don't handle these destructuring assignments properly yet
53 namespace test4
55 void foo()
57 std::map<OUString, OUString> aMap;
58 for (auto & [ rName, rEntry ] : aMap)
60 rEntry.clear();
65 // no warning expected
66 namespace test5
68 struct Struct1
71 void release(Struct1*);
72 void foo(std::list<Struct1*> aList)
74 for (Struct1* pItem : aList)
76 release(pItem);
81 // no warning expected
82 namespace test6
84 void foo(std::vector<std::vector<int>> aVecVec)
86 for (auto& rVec : aVecVec)
87 for (auto& rElement : rVec)
88 rElement = 1;
92 #endif
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */