Fix typo
[LibreOffice.git] / compilerplugins / clang / test / buriedassign.cxx
blob0d9f011939a31a0f89c86e38f82f83894890d876
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 <memory>
12 #include <rtl/ustring.hxx>
14 namespace test1
16 int foo(int);
18 void main()
20 int x = 1;
21 foo(x = 2);
22 // expected-error@-1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
23 int y = x = 1; // no warning expected
24 (void)y;
25 int z = foo(x = 1);
26 // expected-error@-1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
27 (void)z;
28 switch (x = 1)
29 { // expected-error@-1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
31 std::map<int, int> map1;
32 map1[x = 1] = 1;
33 // expected-error@-1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
37 namespace test2
39 struct MyInt
41 int x;
42 MyInt(int i)
43 : x(i)
46 MyInt(MyInt const&) = default;
47 MyInt& operator=(MyInt const&) = default;
48 MyInt& operator=(int) { return *this; }
49 bool operator<(MyInt const& other) const { return x < other.x; }
52 MyInt foo(MyInt);
54 void main()
56 MyInt x = 1;
57 foo(x = 2);
58 // expected-error@-1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
59 MyInt y = x = 1; // no warning expected
60 (void)y;
61 MyInt z = foo(x = 1);
62 // expected-error@-1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
63 (void)z;
64 z = x; // no warning expected
65 std::map<MyInt, int> map1;
66 map1[x = 1] = 1;
67 // expected-error@-1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
71 namespace test3
73 void main(OUString sUserAutoCorrFile, OUString sExt)
75 OUString sRet;
76 if (sUserAutoCorrFile == "xxx")
77 sRet = sUserAutoCorrFile; // no warning expected
78 if (sUserAutoCorrFile == "yyy")
79 (sRet = sUserAutoCorrFile)
80 += sExt; // expected-error@-1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
84 // no warning expected
85 namespace test4
87 struct Task
89 void exec();
91 std::unique_ptr<Task> pop();
93 void foo()
95 std::unique_ptr<Task> pTask;
96 while ((pTask = pop()))
97 pTask->exec();
101 namespace test5
103 void main(OUString sUserAutoCorrFile, int* p2)
105 OUString sRet;
106 int* p1;
107 if (sUserAutoCorrFile == "yyy" && (p1 = p2))
108 sRet = sUserAutoCorrFile;
109 if (sUserAutoCorrFile == "yyy" && nullptr != (p1 = p2))
110 sRet = sUserAutoCorrFile;
111 // expected-error@+1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
112 if (nullptr != (p1 = p2))
113 sRet = sUserAutoCorrFile;
114 // expected-error@+1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
115 if ((p1 = p2) != nullptr)
116 sRet = sUserAutoCorrFile;
117 // expected-error@+1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
118 if ((p1 = p2))
119 sRet = sUserAutoCorrFile;
120 // expected-error@+1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
121 if ((p1 = p2) && sUserAutoCorrFile == "yyy")
122 sRet = sUserAutoCorrFile;
123 // expected-error@+1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
124 if ((p1 = p2) || sUserAutoCorrFile == "yyy")
125 sRet = sUserAutoCorrFile;
126 // expected-error@+1 {{buried assignment, rather put on own line [loplugin:buriedassign]}}
127 if ((p1 = p2) && sUserAutoCorrFile == "yyy")
128 sRet = sUserAutoCorrFile;
129 (void)sRet;
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */