[Libreoffice-commits] core.git: compilerplugins/clang oox/source sal/qa sw/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Wed Feb 10 09:34:16 UTC 2021


 compilerplugins/clang/stringliteralvar.cxx              |    7 ++-
 compilerplugins/clang/test/stringliteralvar.cxx         |    8 ++++
 oox/source/vml/vmldrawing.cxx                           |    4 +-
 sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx |   32 +++++++---------
 sw/source/core/text/itrform2.cxx                        |    4 +-
 sw/source/uibase/shells/textfld.cxx                     |    6 +--
 6 files changed, 34 insertions(+), 27 deletions(-)

New commits:
commit 4cae353cae28f6530544ad5864d4ce3075ac5bcc
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Feb 9 20:48:37 2021 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Wed Feb 10 10:33:25 2021 +0100

    Fix loplugin:stringliteralvar
    
    ...detection of
    
      OUString( const sal_Unicode * value, sal_Int32 length )
    
    ctor.  (On platforms where sal_Int32 is a typedef for int, an argument that
    already is of type int will not be wrapped in an ImplicitCastExpr to the
    sal_Int32 typedef.)
    
    Change-Id: Ifc5456a62d42c1acad76ea949549dc24bd67201a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110654
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/compilerplugins/clang/stringliteralvar.cxx b/compilerplugins/clang/stringliteralvar.cxx
index ed1aa9e717d6..bf06f47f5089 100644
--- a/compilerplugins/clang/stringliteralvar.cxx
+++ b/compilerplugins/clang/stringliteralvar.cxx
@@ -74,7 +74,8 @@ public:
         {
             return true;
         }
-        switch (expr->getConstructor()->getNumParams())
+        auto const ctor = expr->getConstructor();
+        switch (ctor->getNumParams())
         {
             case 1:
             {
@@ -126,7 +127,9 @@ public:
                               .Namespace("libreoffice_internal")
                               .Namespace("rtl")
                               .GlobalNamespace())
-                      || (loplugin::TypeCheck(e2->getType()).Typedef("sal_Int32").GlobalNamespace()
+                      || (loplugin::TypeCheck(ctor->getParamDecl(1)->getType())
+                              .Typedef("sal_Int32")
+                              .GlobalNamespace()
                           && e2->isIntegerConstantExpr(compiler.getASTContext()))))
                 {
                     return true;
diff --git a/compilerplugins/clang/test/stringliteralvar.cxx b/compilerplugins/clang/test/stringliteralvar.cxx
index de67de5c7679..535f0e36ee72 100644
--- a/compilerplugins/clang/test/stringliteralvar.cxx
+++ b/compilerplugins/clang/test/stringliteralvar.cxx
@@ -87,4 +87,12 @@ void f9()
     f(OUString(literal, SAL_N_ELEMENTS(literal)));
 }
 
+void f10()
+{
+    // expected-error at +1 {{change type of variable 'literal' from constant character array ('const sal_Unicode [3]') to OUStringLiteral [loplugin:stringliteralvar]}}
+    static sal_Unicode const literal[] = { 'f', 'o', 'o' };
+    // expected-note at +1 {{first passed into a 'rtl::OUString' constructor here [loplugin:stringliteralvar]}}
+    f(OUString(literal, 3));
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/oox/source/vml/vmldrawing.cxx b/oox/source/vml/vmldrawing.cxx
index 716b07dc6e61..727109b5d3e8 100644
--- a/oox/source/vml/vmldrawing.cxx
+++ b/oox/source/vml/vmldrawing.cxx
@@ -57,8 +57,8 @@ namespace {
 OUString lclGetShapeId( sal_Int32 nShapeId )
 {
     // identifier consists of a literal NUL character, a lowercase 's', and the id
-    sal_Unicode const aStr[2] = { '\0', 's' };
-    return OUString( aStr, 2 ) + OUString::number( nShapeId );
+    static constexpr OUStringLiteral aStr = u"\0s";
+    return aStr + OUString::number( nShapeId );
 }
 
 /** Returns the numeric VML shape identifier from its textual representation. */
diff --git a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx
index 2a4f35e2e793..764b03d8c220 100644
--- a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx
+++ b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx
@@ -81,45 +81,41 @@ void createMessage(
 void test::oustringbuffer::Utf32::appendUtf32() {
     int const str1Len = 3;
     sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
-    int const str2Len = 4;
-    sal_Unicode const str2[str2Len] = { 'a', 'b', 'c', 'd' };
-    int const str3Len = 6;
-    sal_Unicode const str3[str3Len] = { 'a', 'b', 'c', 'd', 0xD800, 0xDC00 };
+    static constexpr OUStringLiteral str2 = u"abcd";
+    static constexpr OUStringLiteral str3 = u"abcd\U00010000";
     OStringBuffer message;
     OUStringBuffer buf1(std::u16string_view(str1, str1Len));
     buf1.appendUtf32('d');
     OUString res1(buf1.makeStringAndClear());
-    createMessage(message, res1, OUString(str2, str2Len));
+    createMessage(message, res1, str2);
     CPPUNIT_ASSERT_EQUAL_MESSAGE(
-        message.getStr(), OUString(str2, str2Len), res1);
-    OUStringBuffer buf2(std::u16string_view(str2, str2Len));
+        message.getStr(), OUString(str2), res1);
+    OUStringBuffer buf2(str2);
     buf2.appendUtf32(0x10000);
     OUString res2(buf2.makeStringAndClear());
-    createMessage(message, res2, OUString(str3, str3Len));
+    createMessage(message, res2, str3);
     CPPUNIT_ASSERT_EQUAL_MESSAGE(
-        message.getStr(), OUString(str3, str3Len), res2);
+        message.getStr(), OUString(str3), res2);
 }
 
 void test::oustringbuffer::Utf32::insertUtf32() {
     int const str1Len = 3;
     sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
-    int const str2Len = 4;
-    sal_Unicode const str2[str2Len] = { 'a', 'b', 'd', 'c' };
-    int const str3Len = 6;
-    sal_Unicode const str3[str3Len] = { 'a', 'b', 0xDBFF, 0xDFFF, 'd', 'c' };
+    static constexpr OUStringLiteral str2 = u"abdc";
+    static constexpr OUStringLiteral str3 = u"ab\U0010FFFFdc";
     OStringBuffer message;
     OUStringBuffer buf1(std::u16string_view(str1, str1Len));
     buf1.insertUtf32(2, 'd');
     OUString res1(buf1.makeStringAndClear());
-    createMessage(message, res1, OUString(str2, str2Len));
+    createMessage(message, res1, str2);
     CPPUNIT_ASSERT_EQUAL_MESSAGE(
-        message.getStr(), OUString(str2, str2Len), res1);
-    OUStringBuffer buf2(std::u16string_view(str2, str2Len));
+        message.getStr(), OUString(str2), res1);
+    OUStringBuffer buf2(str2);
     buf2.insertUtf32(2, 0x10FFFF);
     OUString res2(buf2.makeStringAndClear());
-    createMessage(message, res2, OUString(str3, str3Len));
+    createMessage(message, res2, str3);
     CPPUNIT_ASSERT_EQUAL_MESSAGE(
-        message.getStr(), OUString(str3, str3Len), res2);
+        message.getStr(), OUString(str3), res2);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index fdd4e276b951..2d2ec84a1eed 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -876,8 +876,8 @@ namespace sw::mark {
                 return vListEntries[nCurrentIdx];
         }
 
-        static const sal_Unicode vEnSpaces[ODF_FORMFIELD_DEFAULT_LENGTH] = {8194, 8194, 8194, 8194, 8194};
-        return OUString(vEnSpaces, ODF_FORMFIELD_DEFAULT_LENGTH);
+        static constexpr OUStringLiteral vEnSpaces = u"\u2002\u2002\u2002\u2002\u2002";
+        return vEnSpaces;
     }
 }
 
diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx
index a25de40e60ec..582bcb524bf2 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -690,12 +690,12 @@ FIELD_INSERT:
             if(pCursorPos)
             {
                 // Insert five En Space into the text field so the field has extent
-                static const sal_Unicode vEnSpaces[ODF_FORMFIELD_DEFAULT_LENGTH] = {8194, 8194, 8194, 8194, 8194};
-                bool bSuccess = rSh.GetDoc()->getIDocumentContentOperations().InsertString(*pCursorPos, OUString(vEnSpaces, ODF_FORMFIELD_DEFAULT_LENGTH));
+                static constexpr OUStringLiteral vEnSpaces = u"\u2002\u2002\u2002\u2002\u2002";
+                bool bSuccess = rSh.GetDoc()->getIDocumentContentOperations().InsertString(*pCursorPos, vEnSpaces);
                 if(bSuccess)
                 {
                     IDocumentMarkAccess* pMarksAccess = rSh.GetDoc()->getIDocumentMarkAccess();
-                    SwPaM aFieldPam(pCursorPos->GetPoint()->nNode, pCursorPos->GetPoint()->nContent.GetIndex() - ODF_FORMFIELD_DEFAULT_LENGTH,
+                    SwPaM aFieldPam(pCursorPos->GetPoint()->nNode, pCursorPos->GetPoint()->nContent.GetIndex() - vEnSpaces.getLength(),
                                     pCursorPos->GetPoint()->nNode, pCursorPos->GetPoint()->nContent.GetIndex());
                     pMarksAccess->makeFieldBookmark(aFieldPam, OUString(), ODF_FORMTEXT,
                             aFieldPam.Start());


More information about the Libreoffice-commits mailing list