1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <sal/config.h>
15 #include <rtl/ustring.hxx>
17 // expected-error-re@+1 {{change type of variable 'literal1' from constant character array ('const char{{ ?}}[4]') to OStringLiteral [loplugin:stringliteralvar]}}
18 char const literal1
[] = "foo";
21 // expected-note-re@+1 {{first passed into a '{{(rtl::)?}}OString' constructor here [loplugin:stringliteralvar]}}
25 void f(OUString
const&);
28 // expected-error-re@+1 {{change type of variable 'literal' from constant character array ('const char{{ ?}}[4]') to OUStringLiteral, and make it static [loplugin:stringliteralvar]}}
29 char const literal
[] = "foo";
30 // expected-note-re@+1 {{first passed into a '{{(rtl::)?}}OUString' constructor here [loplugin:stringliteralvar]}}
36 // expected-error-re@+1 {{change type of variable 'literal' from constant character array ('const char16_t{{ ?}}[4]') to OUStringLiteral [loplugin:stringliteralvar]}}
37 static constexpr char16_t literal
[] = u
"foo";
41 // expected-note-re@+1 {{first passed into a '{{(rtl::)?}}OUString' constructor here [loplugin:stringliteralvar]}}
45 std::vector
<OUString
> f4()
47 // expected-error-re@+1 {{change type of variable 'literal' from constant character array ('const char16_t{{ ?}}[4]') to OUStringLiteral [loplugin:stringliteralvar]}}
48 static constexpr char16_t literal
[] = u
"foo";
49 // expected-note@+1 {{first passed into a 'rtl::OUString' constructor here [loplugin:stringliteralvar]}}
55 // expected-error-re@+1 {{variable 'literal' of type 'const {{(rtl::)?}}OUStringLiteral<4>'{{( \(aka 'const rtl::OUStringLiteral<4>'\))?}} with automatic storage duration most likely needs to be static [loplugin:stringliteralvar]}}
56 OUStringLiteral
const literal
= u
"foo";
57 // expected-note-re@+1 {{first converted to '{{(rtl::)?}}OUString' here [loplugin:stringliteralvar]}}
63 // expected-error-re@+1 {{variable 'literal' of type 'const {{(rtl::)?}}OUStringLiteral<4>'{{( \(aka 'const rtl::OUStringLiteral<4>'\))?}} with automatic storage duration most likely needs to be static [loplugin:stringliteralvar]}}
64 constexpr OUStringLiteral literal
= u
"foo";
65 // expected-note-re@+1 {{first converted to '{{(rtl::)?}}OUString' here [loplugin:stringliteralvar]}}
71 static constexpr OUStringLiteral
const literal
= u
"foo";
77 static constexpr OUStringLiteral
const literal
= u
"foo";
78 // expected-error-re@+1 {{variable 'literal' of type 'const {{(rtl::)?}}OUStringLiteral<4>'{{( \(aka 'const rtl::OUStringLiteral<4>'\))?}} suspiciously used in a sizeof expression [loplugin:stringliteralvar]}}
84 // expected-error-re@+1 {{change type of variable 'literal' from constant character array ('const sal_Unicode{{ ?}}[3]'{{( \(aka 'const char16_t\[3\]'\))?}}) to OUStringLiteral [loplugin:stringliteralvar]}}
85 static sal_Unicode
const literal
[] = { 'f', 'o', 'o' };
86 // expected-note-re@+1 {{first passed into a '{{(rtl::)?}}OUString' constructor here [loplugin:stringliteralvar]}}
87 f(OUString(literal
, std::size(literal
)));
92 // expected-error-re@+1 {{change type of variable 'literal' from constant character array ('const sal_Unicode{{ ?}}[3]'{{( \(aka 'const char16_t\[3\]'\))?}}) to OUStringLiteral [loplugin:stringliteralvar]}}
93 static sal_Unicode
const literal
[] = { 'f', 'o', 'o' };
94 // expected-note-re@+1 {{first passed into a '{{(rtl::)?}}OUString' constructor here [loplugin:stringliteralvar]}}
95 f(OUString(literal
, 3));
98 void f11(int nStreamType
)
100 // expected-error-re@+1 {{change type of variable 'sDocumentType' from constant character array ('const char{{ ?}}[4]') to OUStringLiteral, and make it static [loplugin:stringliteralvar]}}
101 const char sDocumentType
[] = "foo";
102 OUString sStreamType
;
106 // expected-note@+1 {{first assigned here [loplugin:stringliteralvar]}}
107 sStreamType
= sDocumentType
;
113 extern sal_Unicode
const extarr
[1];
119 // Suppress warnings if the array contains a malformed sequence of UTF-16 code units...:
120 static sal_Unicode
const arr1
[] = { 0xD800 };
121 f(OUString(arr1
, 1));
122 // ...Or potentially contains a malformed sequence of UTF-16 code units...:
123 f(OUString(extarr
, 1));
124 sal_Unicode
const arr2
[] = { init() };
125 f(OUString(arr2
, 1));
126 // ...But generate a warning if the array contains a well-formed sequence of UTF-16 code units
127 // containing surrogates:
128 // expected-error-re@+1 {{change type of variable 'arr3' from constant character array ('const sal_Unicode{{ ?}}[2]'{{( \(aka 'const char16_t\[2\]'\))?}}) to OUStringLiteral [loplugin:stringliteralvar]}}
129 static sal_Unicode
const arr3
[] = { 0xD800, 0xDC00 };
130 // expected-note-re@+1 {{first passed into a '{{(rtl::)?}}OUString' constructor here [loplugin:stringliteralvar]}}
131 f(OUString(arr3
, 2));
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */