diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2023-10-10 13:41:35 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2023-10-11 09:19:35 +0200 |
commit | f99bee8103ad82dac2e53e114527399c4af5485c (patch) | |
tree | 0708413c61a0a2b7ee8a7e5a7ee633c410d972b6 /compilerplugins | |
parent | a822df6379606ab9f62d6ebb2318d0294d9c959c (diff) |
Delete OUString UTF-16 string literal ctor/assignment op
...that have been made unused by 7ef3d937415185ef66e32dd3043783eddcd03db5
"loplugin:ostr: Rewrite some uses of O[U]String to use ""_ostr/u""_ustr
literals". (And which means we can remove the relevant code from that plugin
again.)
(This also found a handful of remaining uses that had been hard for the plugin
to discover, along the lines of
> std::map<OUString, int> m = {{u"foo", 0}};
being represented by a
> DeclStmt 0xdaca578 <line:103:5, col:50>
> `-VarDecl 0xdac9150 <col:5, col:49> col:29 s11 'std::map<OUString, int>':'std::map<rtl::OUString, int>' cinit destroyed
> `-ExprWithCleanups 0xdaca548 <col:35, col:49> 'std::map<OUString, int>':'std::map<rtl::OUString, int>'
> `-CXXConstructExpr 0xdaca508 <col:35, col:49> 'std::map<OUString, int>':'std::map<rtl::OUString, int>' 'void (initializer_list<value_type>, const std::less<rtl::OUString> &, const allocator_type &)' list std::initializer_list
> |-CXXStdInitializerListExpr 0xdaca480 <col:35, col:49> 'initializer_list<value_type>':'std::initializer_list<std::pair<const rtl::OUString, int>>'
> | `-MaterializeTemporaryExpr 0xdaca468 <col:35, col:49> 'const std::pair<const rtl::OUString, int>[1]' xvalue
> | `-CXXBindTemporaryExpr 0xdaca448 <col:35, col:49> 'const std::pair<const rtl::OUString, int>[1]' (CXXTemporary 0xdaca448)
> | `-InitListExpr 0xdac9df0 <col:35, col:49> 'const std::pair<const rtl::OUString, int>[1]'
> | `-CXXConstructExpr 0xdaca408 <col:36, col:48> 'const std::pair<const rtl::OUString, int>' 'void (const char16_t (&)[4], int &&) noexcept(_S_nothrow_constructible<const char16_t (&)[4], int>())' list
> | |-StringLiteral 0xdac91b8 <col:38> 'const char16_t[4]' lvalue u"foo"
> | `-MaterializeTemporaryExpr 0xdaca3f0 <col:46> 'int' xvalue
> | `-IntegerLiteral 0xdac91d8 <col:46> 'int' 0
> |-CXXDefaultArgExpr 0xdaca498 <<invalid sloc>> 'const std::less<rtl::OUString>':'const std::less<rtl::OUString>' lvalue
> `-CXXDefaultArgExpr 0xdaca4b8 <<invalid sloc>> 'const allocator_type':'const std::allocator<std::pair<const rtl::OUString, int>>' lvalue
Clang AST.)
Change-Id: I496fe9d4d5e1a033cb7b27b4e04b303f8ddbed4a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157756
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/ostr.cxx | 90 | ||||
-rw-r--r-- | compilerplugins/clang/test/ostr.cxx | 40 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringconstant.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringliteralvar.cxx | 6 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringstatic.cxx | 7 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringview.cxx | 2 |
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]}} |