bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / test / buriedassign.cxx
blob7e41a83ccaa52453bd96ab44af3d08f962d686d8
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 <map>
11 #include <rtl/ustring.hxx>
13 namespace test1
15 int foo(int);
17 void main()
19 int x = 1;
20 foo(x = 2); // expected-error {{buried assignment, very hard to read [loplugin:buriedassign]}}
21 int y = x = 1; // no warning expected
22 (void)y;
23 int z = foo(
24 x = 1); // expected-error {{buried assignment, very hard to read [loplugin:buriedassign]}}
25 (void)z;
26 switch (x = 1)
27 { // expected-error@-1 {{buried assignment, very hard to read [loplugin:buriedassign]}}
29 std::map<int, int> map1;
30 map1[x = 1]
31 = 1; // expected-error@-1 {{buried assignment, very hard to read [loplugin:buriedassign]}}
35 namespace test2
37 struct MyInt
39 int x;
40 MyInt(int i)
41 : x(i)
44 MyInt& operator=(MyInt const&) = default;
45 MyInt& operator=(int) { return *this; }
46 bool operator<(MyInt const& other) const { return x < other.x; }
49 MyInt foo(MyInt);
51 void main()
53 MyInt x = 1;
54 foo(x = 2); // expected-error {{buried assignment, very hard to read [loplugin:buriedassign]}}
55 MyInt y = x = 1; // no warning expected
56 (void)y;
57 MyInt z = foo(
58 x = 1); // expected-error {{buried assignment, very hard to read [loplugin:buriedassign]}}
59 (void)z;
60 z = x; // no warning expected
61 std::map<MyInt, int> map1;
62 map1[x = 1]
63 = 1; // expected-error@-1 {{buried assignment, very hard to read [loplugin:buriedassign]}}
67 namespace test3
69 void main(OUString sUserAutoCorrFile, OUString sExt)
71 OUString sRet;
72 if (sUserAutoCorrFile == "xxx")
73 sRet = sUserAutoCorrFile; // no warning expected
74 if (sUserAutoCorrFile == "yyy")
75 (sRet = sUserAutoCorrFile)
76 += sExt; // expected-error@-1 {{buried assignment, very hard to read [loplugin:buriedassign]}}
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */