nss: upgrade to release 3.73
[LibreOffice.git] / compilerplugins / clang / test / stringview.cxx
blob3c15d9cc443799cfda726d62fc801f7c30276da7
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 <rtl/strbuf.hxx>
11 #include <rtl/string.hxx>
12 #include <rtl/ustrbuf.hxx>
13 #include <rtl/ustring.hxx>
15 void call_view(std::u16string_view) {}
16 void call_view(std::string_view) {}
17 struct ConstructWithView
19 ConstructWithView(std::u16string_view) {}
20 ConstructWithView(std::string_view) {}
23 namespace test1
25 void f1(std::u16string_view s1)
27 // no warning expected
28 call_view(s1);
30 void f1(std::string_view s1)
32 // no warning expected
33 call_view(s1);
35 void f1(OUString s1)
37 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
38 call_view(s1.copy(1, 2));
39 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
40 call_view(s1.copy(1));
41 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
42 ConstructWithView(s1.copy(1, 2));
43 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
44 ConstructWithView(s1.copy(1));
46 void f1(OString s1)
48 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
49 call_view(s1.copy(1, 2));
50 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
51 call_view(s1.copy(1));
52 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
53 ConstructWithView(s1.copy(1, 2));
54 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
55 ConstructWithView(s1.copy(1));
59 namespace test2
61 void f3(OUString s1)
63 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
64 OUString s2 = s1.copy(1, 2) + "xxx";
65 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
66 s2 = s1.copy(1) + "xxx";
67 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
68 s2 = "xxx" + s1.copy(1);
69 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
70 s2 += s1.copy(1);
72 void f3(OString s1)
74 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
75 OString s2 = s1.copy(1, 2) + "xxx";
76 (void)s2;
77 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
78 OString s3 = s1.copy(1) + "xxx";
79 (void)s3;
83 namespace test3
85 void f4(OUString s1, OUString s2)
87 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
88 sal_Unicode x = s2.copy(1, 2)[12];
89 (void)x;
90 // expected-error@+1 {{rather than copy, pass with a view using subView() [loplugin:stringview]}}
91 if (s2.copy(1, 2) < s1)
96 void f5()
98 // expected-error@+1 {{instead of an empty 'rtl::OString', pass an empty 'std::string_view' [loplugin:stringview]}}
99 call_view(OString());
100 // expected-error@+1 {{instead of an empty 'rtl::OUString', pass an empty 'std::u16string_view' [loplugin:stringview]}}
101 call_view(OUString());
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */