summaryrefslogtreecommitdiff
path: root/compilerplugins/clang
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2023-11-15 15:05:59 +0100
committerStephan Bergmann <sbergman@redhat.com>2023-11-15 19:16:51 +0100
commit51d9c9899f54200a2bf9bf49df16c03cca403498 (patch)
tree275450354a16126012994a58b390a294cab0d499 /compilerplugins/clang
parentf9b9e702465b4de29153b49e077c70a0ad78c89d (diff)
Extend a loplugin:ostr check from OUString to OString
Change-Id: I0776ab0ab376d6181461d2c144a4107b06233829 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159470 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r--compilerplugins/clang/ostr.cxx19
-rw-r--r--compilerplugins/clang/test/ostr.cxx82
2 files changed, 75 insertions, 26 deletions
diff --git a/compilerplugins/clang/ostr.cxx b/compilerplugins/clang/ostr.cxx
index 16d8f32dbc0e..da68451e6316 100644
--- a/compilerplugins/clang/ostr.cxx
+++ b/compilerplugins/clang/ostr.cxx
@@ -285,10 +285,6 @@ public:
i->second.explicitConversions.insert(expr);
return true;
}
- if (!utf16)
- {
- return true;
- }
if (expr->getNumArgs() != 2)
{
return true;
@@ -306,9 +302,8 @@ public:
{
return true;
}
- if (!compat::isOrdinary(e2))
+ if (!(compat::isOrdinary(e2) || e2->isUTF8()))
{
- assert(!e2->isUTF8()); //TODO
return true;
}
auto const temp = isa<CXXTemporaryObjectExpr>(expr)
@@ -369,17 +364,19 @@ public:
Lexer::MeasureTokenLength(l3, compiler.getSourceManager(), compiler.getLangOpts()));
l4 = l4.getLocWithOffset(
Lexer::MeasureTokenLength(l4, compiler.getSourceManager(), compiler.getLangOpts()));
- if (replaceText(l1, delta(l1, l2), macroBegin ? "u\"\" " : "u")
- && replaceText(l3, delta(l3, l4), macroEnd ? " \"\"_ustr" : "_ustr"))
+ if ((!utf16 || replaceText(l1, delta(l1, l2), macroBegin ? "u\"\" " : "u"))
+ && replaceText(l3, delta(l3, l4),
+ utf16 ? (macroEnd ? " \"\"_ustr" : "_ustr")
+ : (macroEnd ? " \"\"_ostr" : "_ostr")))
{
return true;
}
}
report(DiagnosticsEngine::Warning,
- "use a _ustr user-defined string literal instead of constructing an instance of %0 "
- "from an ordinary string literal",
+ "use a %select{_ostr|_ustr}0 user-defined string literal instead of constructing an"
+ " instance of %1 from an ordinary string literal",
expr->getExprLoc())
- << expr->getType().getLocalUnqualifiedType() << expr->getSourceRange();
+ << utf16 << expr->getType().getLocalUnqualifiedType() << expr->getSourceRange();
return true;
}
diff --git a/compilerplugins/clang/test/ostr.cxx b/compilerplugins/clang/test/ostr.cxx
index 22cafc731d3e..8e772b1258a2 100644
--- a/compilerplugins/clang/test/ostr.cxx
+++ b/compilerplugins/clang/test/ostr.cxx
@@ -21,7 +21,9 @@ struct S
OUString s;
};
-void f(OUString const&);
+void takeOstring(OString const&);
+
+void takeOustring(OUString const&);
void f(OUString const&, OUString const&);
@@ -35,30 +37,80 @@ void takeStdView(std::u16string_view);
void f()
{
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ OString s1o = "foo";
+ (void)s1o;
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ OString s2o = (("foo"));
+ (void)s2o;
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ OString s3o("foo");
+ (void)s3o;
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ OString s4o((("foo")));
+ (void)s4o;
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring(OString("foo"));
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring(((OString((("foo"))))));
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring(OString("foo", rtl::libreoffice_internal::Dummy()));
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring(((OString((("foo")), rtl::libreoffice_internal::Dummy()))));
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring("foo");
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring((("foo")));
+
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ OString s1o8 = u8"foo";
+ (void)s1o8;
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ OString s2o8 = ((u8"foo"));
+ (void)s2o8;
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ OString s3o8(u8"foo");
+ (void)s3o8;
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ OString s4o8(((u8"foo")));
+ (void)s4o8;
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring(OString(u8"foo"));
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring(((OString(((u8"foo"))))));
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring(OString(u8"foo", rtl::libreoffice_internal::Dummy()));
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring(((OString(((u8"foo")), rtl::libreoffice_internal::Dummy()))));
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring(u8"foo");
+ // expected-error-re@+1 {{use a _ostr user-defined string literal instead of constructing an instance of '{{(rtl::)?}}OString' from an ordinary string literal [loplugin:ostr]}}
+ takeOstring(((u8"foo")));
+
// 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]}}
- OUString s1 = "foo";
- (void)s1;
+ OUString s1u = "foo";
+ (void)s1u;
// 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]}}
- OUString s2 = (("foo"));
- (void)s2;
+ OUString s2u = (("foo"));
+ (void)s2u;
// 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]}}
- OUString s3("foo");
- (void)s3;
+ OUString s3u("foo");
+ (void)s3u;
// 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]}}
- OUString s4((("foo")));
- (void)s4;
+ OUString s4u((("foo")));
+ (void)s4u;
// 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(OUString("foo"));
+ takeOustring(OUString("foo"));
// 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(((OUString((("foo"))))));
+ takeOustring(((OUString((("foo"))))));
// 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(OUString("foo", rtl::libreoffice_internal::Dummy()));
+ takeOustring(OUString("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 an ordinary string literal [loplugin:ostr]}}
- f(((OUString((("foo")), rtl::libreoffice_internal::Dummy()))));
+ takeOustring(((OUString((("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 an ordinary string literal [loplugin:ostr]}}
- f("foo");
+ takeOustring("foo");
// 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")));
+ takeOustring((("foo")));
// 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]}}
S s10 = { "foo" };