nss: upgrade to release 3.73
[LibreOffice.git] / compilerplugins / clang / test / redundantfcast.cxx
blob255c1d44b2a74d461174beafc59eb7f54a8b9606
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 "sal/config.h"
12 #include "rtl/ustring.hxx"
13 #include "tools/color.hxx"
15 #include <functional>
16 #include <initializer_list>
17 #include <memory>
19 void method1(OUString const&); // expected-note {{in call to method here [loplugin:redundantfcast]}}
21 struct Foo
23 Foo(int) {}
26 void func1(Foo const& f); // expected-note {{in call to method here [loplugin:redundantfcast]}}
28 namespace tools
30 struct Polygon
32 Polygon() = default;
34 struct PolyPolygon
36 PolyPolygon(
37 Polygon const&); // expected-note {{in call to method here [loplugin:redundantfcast]}}
41 void ImplWritePolyPolygonRecord(const tools::PolyPolygon& rPolyPoly);
43 int main()
45 OUString s;
46 (void)OUString(
47 s); // expected-error@-1 {{redundant functional cast from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantfcast]}}
48 using T1 = OUString;
49 (void)T1(
50 s); // expected-error@-1 {{redundant functional cast from 'rtl::OUString' to 'T1' (aka 'rtl::OUString') [loplugin:redundantfcast]}}
51 using T2 = OUString const;
52 (void)T2(
53 s); // expected-error@-1 {{redundant functional cast from 'rtl::OUString' to 'T2' (aka 'const rtl::OUString') [loplugin:redundantfcast]}}
55 (void)std::unique_ptr<int>(std::unique_ptr<int>(
56 new int{})); // expected-error@-1 {{redundant functional cast from 'std::unique_ptr<int>' to 'std::unique_ptr<int>' [loplugin:redundantfcast]}}
58 OUString s1;
59 method1(OUString(
60 s1)); // expected-error@-1 {{redundant functional cast from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantfcast]}}
61 OUString s2;
62 s2 = OUString(
63 s1); // expected-error@-1 {{redundant functional cast from 'rtl::OUString' to 'rtl::OUString' [loplugin:redundantfcast]}}
65 Color col1;
66 Color col2 = Color(
67 col1); // expected-error@-1 {{redundant functional cast from 'Color' to 'Color' [loplugin:redundantfcast]}}
68 (void)col2;
70 Foo foo(1);
71 func1(Foo(
72 foo)); // expected-error@-1 {{redundant functional cast from 'Foo' to 'Foo' [loplugin:redundantfcast]}}
74 const tools::Polygon aPolygon;
75 ImplWritePolyPolygonRecord(tools::PolyPolygon(tools::Polygon(
76 aPolygon))); // expected-error@-1 {{redundant functional cast from 'const tools::Polygon' to 'tools::Polygon' [loplugin:redundantfcast]}}
79 class Class1
81 Foo foo;
82 Foo func2()
84 return Foo(
85 foo); // expected-error@-1 {{redundant functional cast from 'Foo' to 'Foo' [loplugin:redundantfcast]}}
89 // casting of lambdas
90 namespace test5
92 void f1(std::function<void()> x);
93 void f2()
95 // expected-error-re@+1 {{redundant functional cast {{.+}} [loplugin:redundantfcast]}}
96 f1(std::function([&]() {}));
99 namespace test6
101 void f1(std::function<void(int)>);
102 void f1(std::function<void(long)>);
103 void f2()
105 f1(std::function<void(long)>([&](int) {})); // should not warn here
109 namespace test7
111 // expected-note@+1 6 {{in call to method here [loplugin:redundantfcast]}}
112 void f1(std::initializer_list<int> const&);
113 // expected-note@+1 6 {{in call to method here [loplugin:redundantfcast]}}
114 template <typename T> void f2(std::initializer_list<T> const&);
115 // expected-note@+1 4 {{in call to method here [loplugin:redundantfcast]}}
116 template <typename T> void f3(T const&);
117 // expected-note@+1 4 {{in call to method here [loplugin:redundantfcast]}}
118 template <typename... T> void f4(T const&...);
119 void f5(int, ...);
120 void g(std::initializer_list<int> il)
122 f1(il);
123 f2(il);
124 f3(il);
125 f4(il);
126 f5(0, il);
127 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
128 f1(std::initializer_list<int>(il));
129 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
130 f2(std::initializer_list<int>(il));
131 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
132 f3(std::initializer_list<int>(il));
133 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
134 f4(std::initializer_list<int>(il));
135 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
136 f5(0, std::initializer_list<int>(il));
137 f1({});
138 f1(std::initializer_list<int>{}); // should warn, but not modelled as CXXFunctionalCastExpr
139 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
140 f1(std::initializer_list<int>({}));
141 // f2({}); //error
142 f2(std::initializer_list<int>{}); // should warn, but not modelled as CXXFunctionalCastExpr
143 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
144 f2(std::initializer_list<int>({}));
145 // f3({}); //error
146 f3(std::initializer_list<int>{}); // (not modelled as CXXFunctionalCastExpr anyway)
147 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
148 f3(std::initializer_list<int>({})); // arguably rather subtle, remove "("...")"
149 // f4({}); //error
150 f4(std::initializer_list<int>{}); // (not modelled as CXXFunctionalCastExpr anyway)
151 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
152 f4(std::initializer_list<int>({})); // arguably rather subtle, remove "("...")"
153 // f5(0, {}); //error
154 f5(0, std::initializer_list<int>{}); // (not modelled as CXXFunctionalCastExpr anyway)
155 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
156 f5(0, std::initializer_list<int>({})); // arguably rather subtle, remove "("...")"
157 f1({ 1 });
158 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
159 f1(std::initializer_list<int>{ 1 });
160 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
161 f1(std::initializer_list<int>({ 1 }));
162 f2({ 1 });
163 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
164 f2(std::initializer_list<int>{ 1 });
165 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
166 f2(std::initializer_list<int>({ 1 }));
167 // f3({1}); //error
168 f3(std::initializer_list<int>{ 1 });
169 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
170 f3(std::initializer_list<int>({ 1 })); // arguably rather subtle, remove "("...")"
171 // f4({1}); //error
172 f4(std::initializer_list<int>{ 1 });
173 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
174 f4(std::initializer_list<int>({ 1 })); // arguably rather subtle, remove "("...")"
175 // f5(0, {1}); //error
176 f5(0, std::initializer_list<int>{ 1 });
177 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
178 f5(0, std::initializer_list<int>({ 1 })); // arguably rather subtle, remove "("...")"
179 f1({ 1, 2, 3 });
180 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
181 f1(std::initializer_list<int>{ 1, 2, 3 });
182 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
183 f1(std::initializer_list<int>({ 1, 2, 3 }));
184 f2({ 1, 2, 3 });
185 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
186 f2(std::initializer_list<int>{ 1, 2, 3 });
187 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
188 f2(std::initializer_list<int>({ 1, 2, 3 }));
189 // f3({1, 2, 3}); //error
190 f3(std::initializer_list<int>{ 1, 2, 3 });
191 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
192 f3(std::initializer_list<int>({ 1, 2, 3 })); // arguably rather subtle, remove "("...")"
193 // f4({1, 2, 3}); //error
194 f4(std::initializer_list<int>{ 1, 2, 3 });
195 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
196 f4(std::initializer_list<int>({ 1, 2, 3 })); // arguably rather subtle, remove "("...")"
197 // f5(0, {1, 2, 3}); //error
198 f5(0, std::initializer_list<int>{ 1, 2, 3 });
199 // expected-error@+1 {{redundant functional cast from 'std::initializer_list<int>' to 'std::initializer_list<int>' [loplugin:redundantfcast]}}
200 f5(0, std::initializer_list<int>({ 1, 2, 3 })); // arguably rather subtle, remove "("...")"
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */