summaryrefslogtreecommitdiff
path: root/compilerplugins/clang
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r--compilerplugins/clang/ostr.cxx90
-rw-r--r--compilerplugins/clang/test/ostr.cxx40
-rw-r--r--compilerplugins/clang/test/stringconstant.cxx2
-rw-r--r--compilerplugins/clang/test/stringliteralvar.cxx6
-rw-r--r--compilerplugins/clang/test/stringstatic.cxx7
-rw-r--r--compilerplugins/clang/test/stringview.cxx2
6 files changed, 9 insertions, 138 deletions
diff --git a/compilerplugins/clang/ostr.cxx b/compilerplugins/clang/ostr.cxx
index 13fd5df0b29a..462916641421 100644
--- a/compilerplugins/clang/ostr.cxx
+++ b/compilerplugins/clang/ostr.cxx
@@ -97,7 +97,7 @@ public:
{
return true;
}
- if (!(compat::isOrdinary(e2) || e2->isUTF16()))
+ if (!compat::isOrdinary(e2))
{
assert(!e2->isUTF8()); //TODO
return true;
@@ -148,7 +148,7 @@ public:
{
return true;
}
- if (!(e2->isUTF16() || compiler.getDiagnosticOpts().VerifyDiagnostics))
+ if (!compiler.getDiagnosticOpts().VerifyDiagnostics)
{
//TODO: Leave rewriting these uses of ordinary string literals for later (but already
// cover them when verifying CompilerTest_compilerplugins_clang):
@@ -160,8 +160,7 @@ public:
Lexer::MeasureTokenLength(l3, compiler.getSourceManager(), compiler.getLangOpts()));
l4 = l4.getLocWithOffset(
Lexer::MeasureTokenLength(l4, compiler.getSourceManager(), compiler.getLangOpts()));
- if ((e2->isUTF16() ? removeText(l1, delta(l1, l2))
- : replaceText(l1, delta(l1, l2), macroBegin ? "u\"\" " : "u"))
+ if (replaceText(l1, delta(l1, l2), macroBegin ? "u\"\" " : "u")
&& replaceText(l3, delta(l3, l4), macroEnd ? " \"\"_ustr" : "_ustr"))
{
return true;
@@ -169,88 +168,9 @@ public:
}
report(DiagnosticsEngine::Warning,
"use a _ustr user-defined string literal instead of constructing an instance of %0 "
- "from %select{an ordinary|a UTF-16}1 string literal",
+ "from an ordinary string literal",
expr->getExprLoc())
- << expr->getType().getLocalUnqualifiedType() << e2->isUTF16() << expr->getSourceRange();
- return true;
- }
-
- bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* expr)
- {
- if (ignoreLocation(expr))
- {
- return true;
- }
- if (expr->getOperator() != OO_Equal)
- {
- return true;
- }
- if (!loplugin::TypeCheck(expr->getArg(0)->getType())
- .Class("OUString")
- .Namespace("rtl")
- .GlobalNamespace())
- {
- return true;
- }
- auto const e2 = dyn_cast<clang::StringLiteral>(expr->getArg(1)->IgnoreParenImpCasts());
- if (e2 == nullptr)
- {
- return true;
- }
- if (!e2->isUTF16())
- {
- return true;
- }
- if (rewriter != nullptr)
- {
- if (insertTextAfterToken(e2->getEndLoc(), "_ustr"))
- {
- return true;
- }
- }
- report(DiagnosticsEngine::Warning,
- "use a _ustr user-defined string literal instead of assigning from a UTF-16 string"
- " literal",
- expr->getExprLoc())
- << expr->getSourceRange();
- return true;
- }
-
- bool VisitCXXMemberCallExpr(CXXMemberCallExpr const* expr)
- {
- if (ignoreLocation(expr))
- {
- return true;
- }
- if (!loplugin::DeclCheck(expr->getMethodDecl()).Operator(OO_Equal))
- {
- return true;
- }
- if (!loplugin::TypeCheck(expr->getObjectType())
- .Class("OUString")
- .Namespace("rtl")
- .GlobalNamespace())
- {
- return true;
- }
- auto const e2 = dyn_cast<clang::StringLiteral>(expr->getArg(0)->IgnoreParenImpCasts());
- if (e2 == nullptr)
- {
- return true;
- }
- if (!e2->isUTF16())
- {
- return true;
- }
- if (rewriter != nullptr)
- {
- //TODO
- }
- report(DiagnosticsEngine::Warning,
- "use a _ustr user-defined string literal instead of assigning from a UTF-16 string"
- " literal",
- expr->getExprLoc())
- << expr->getSourceRange();
+ << expr->getType().getLocalUnqualifiedType() << expr->getSourceRange();
return true;
}
diff --git a/compilerplugins/clang/test/ostr.cxx b/compilerplugins/clang/test/ostr.cxx
index 8f705a8f7215..6a09728f3ff6 100644
--- a/compilerplugins/clang/test/ostr.cxx
+++ b/compilerplugins/clang/test/ostr.cxx
@@ -49,50 +49,10 @@ void f()
// expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from an ordinary string literal [loplugin:ostr]}}
f((("foo")));
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- OUString s5 = u"foo";
- (void)s5;
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- OUString s6 = ((u"foo"));
- (void)s6;
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- OUString s7(u"foo");
- (void)s7;
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- OUString s8(((u"foo")));
- (void)s8;
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- f(OUString(u"foo"));
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- f(((OUString(((u"foo"))))));
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- f(OUString(u"foo", rtl::libreoffice_internal::Dummy()));
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- f(((OUString(((u"foo")), rtl::libreoffice_internal::Dummy()))));
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- f(u"foo");
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- f(((u"foo")));
-
- OUString s9;
- // expected-error@+1 {{use a _ustr user-defined string literal instead of assigning from a UTF-16 string literal [loplugin:ostr]}}
- s9 = u"foo";
- // expected-error@+1 {{use a _ustr user-defined string literal instead of assigning from a UTF-16 string literal [loplugin:ostr]}}
- s9 = ((u"foo"));
- // expected-error@+1 {{use a _ustr user-defined string literal instead of assigning from a UTF-16 string literal [loplugin:ostr]}}
- s9.operator=(u"foo");
- // expected-error@+1 {{use a _ustr user-defined string literal instead of assigning from a UTF-16 string literal [loplugin:ostr]}}
- s9.operator=(((u"foo")));
-
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- S s10 = { u"foo" };
-
// Only generate one warning here, not two, for a macro argument used twice in the macro's
// expansion:
// expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from an ordinary string literal [loplugin:ostr]}}
M("foo");
- // expected-error-re@+1 {{use a _ustr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OUString' from a UTF-16 string literal [loplugin:ostr]}}
- M(u"foo");
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/test/stringconstant.cxx b/compilerplugins/clang/test/stringconstant.cxx
index ada901b877ce..1c9fbf192f6d 100644
--- a/compilerplugins/clang/test/stringconstant.cxx
+++ b/compilerplugins/clang/test/stringconstant.cxx
@@ -139,8 +139,6 @@ int main() {
OUString().getStr();
// expected-error-re@+1 {{in call of 'rtl::OUString::getStr', replace '{{(rtl::)?}}OUString' constructed from a string literal directly with a UTF-16 string literal}}
OUString("foo").getStr();
- // expected-error-re@+1 {{in call of 'rtl::OUString::getStr', replace '{{(rtl::)?}}OUString' constructed from a string literal directly with the string literal}}
- OUString(u"foo").getStr();
}
diff --git a/compilerplugins/clang/test/stringliteralvar.cxx b/compilerplugins/clang/test/stringliteralvar.cxx
index d0fdcedb0668..6ea7c184c644 100644
--- a/compilerplugins/clang/test/stringliteralvar.cxx
+++ b/compilerplugins/clang/test/stringliteralvar.cxx
@@ -39,15 +39,15 @@ struct S3
void f3()
{
// expected-note-re@+1 {{first passed into a '{{(rtl::)?}}OUString' constructor here [loplugin:stringliteralvar]}}
- f(S3::literal);
+ f(OUString(S3::literal, 3));
}
std::vector<OUString> f4()
{
// expected-error-re@+1 {{change type of variable 'literal' from constant character array ('const char16_t{{ ?}}[4]') to OUStringLiteral [loplugin:stringliteralvar]}}
static constexpr char16_t literal[] = u"foo";
- // expected-note@+1 {{first passed into a 'rtl::OUString' constructor here [loplugin:stringliteralvar]}}
- return { literal };
+ // expected-note-re@+1 {{first passed into a '{{(rtl::)?}}OUString' constructor here [loplugin:stringliteralvar]}}
+ return { OUString(literal, 3) };
}
void f5()
diff --git a/compilerplugins/clang/test/stringstatic.cxx b/compilerplugins/clang/test/stringstatic.cxx
index 20326101dc79..bfe92b69f598 100644
--- a/compilerplugins/clang/test/stringstatic.cxx
+++ b/compilerplugins/clang/test/stringstatic.cxx
@@ -28,10 +28,3 @@ void test2()
static const OUString DATA = "xxx";
f(DATA.pData);
}
-
-void test3()
-{
- // expected-error@+1 {{rather declare this using OUStringLiteral/OStringLiteral/char[] [loplugin:stringstatic]}}
- OUString const literal = u"foo";
- f(literal);
-}
diff --git a/compilerplugins/clang/test/stringview.cxx b/compilerplugins/clang/test/stringview.cxx
index b7284cd5ed57..a8df9dd6b179 100644
--- a/compilerplugins/clang/test/stringview.cxx
+++ b/compilerplugins/clang/test/stringview.cxx
@@ -173,7 +173,7 @@ void f5(char const* s1, sal_Int32 n1, char16_t const* s2, sal_Int32 n2, OString
// expected-error-re@+1 {{instead of an '{{(rtl::)?}}OUString' constructed from a 'const char{{ ?}}[4]', pass a 'std::u16string_view' [loplugin:stringview]}}
call_view(OUString("foo"));
// expected-error-re@+1 {{instead of an '{{(rtl::)?}}OUString' constructed from a 'const char16_t{{ ?}}[4]', pass a 'std::u16string_view' [loplugin:stringview]}}
- call_view(OUString(u"foo"));
+ call_view(OUString(u"foo", 3));
// expected-error-re@+1 {{instead of an '{{(rtl::)?}}OUString' constructed from a 'const char', pass a 'std::u16string_view' (or an 'rtl::OUStringChar') [loplugin:stringview]}}
call_view(OUString(*s1));
// expected-error-re@+1 {{instead of an '{{(rtl::)?}}OUString' constructed from a 'const char16_t', pass a 'std::u16string_view' (or an 'rtl::OUStringChar') [loplugin:stringview]}}