chart2/qa/extras/chart2dump/chart2dump.cxx                |   10 ++---
 connectivity/source/drivers/hsqldb/HDriver.cxx            |    8 +---
 dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx     |    2 -
 i18npool/source/indexentry/indexentrysupplier_default.cxx |    2 -
 include/o3tl/nonstaticstring.hxx                          |   27 ++++++++++++++
 include/oox/core/relations.hxx                            |    2 -
 include/toolkit/helper/macros.hxx                         |    2 -
 include/vbahelper/vbahelperinterface.hxx                  |    2 -
 sal/qa/rtl/alloc/rtl_alloc.cxx                            |    3 +
 sax/source/expatwrap/sax_expat.cxx                        |    2 -
 sc/qa/unit/ucalc.cxx                                      |   11 +++--
 svl/qa/unit/svl.cxx                                       |   19 +++++----
 vbahelper/source/vbahelper/vbafontbase.cxx                |    2 -
 vcl/workben/vcldemo.cxx                                   |    2 -
 14 files changed, 61 insertions(+), 33 deletions(-)

New commits:
commit d98e014cf6d4cea7ebd7898cbc9124f6fba07684
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Fri Oct 6 16:51:17 2023 +0200
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Sun Apr 28 11:29:52 2024 +0200

    Extended loplugin:ostr manual changes
    
    I had done these a while ago, when I looked into extending loplugin:ostr to 
do
    more automatic rewriting, and these were places where I needed to do 
something
    manually, for one reason or another, because the automatic rewriting would 
not
    pick it up correctly.
    
    However, I got distracted, and a wholesale automatic rewrite would still run
    into cases where an _ostr/_ustr instance from a library's .rodata would 
still be
    referenced after the library has already been dlcose'd.  So I never came 
around
    to finishing all that.
    
    But there appears to be renewed interest in (automatic) rewritings here 
now, so
    it probably makes sense if I share this part of my work anyway.
    
    Change-Id: I3da9d38398e4bca373cb0000a9d34b49a36ad58a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166792
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>
    Tested-by: Jenkins

diff --git a/chart2/qa/extras/chart2dump/chart2dump.cxx 
b/chart2/qa/extras/chart2dump/chart2dump.cxx
index d13d768c032f..f8cf7ad2d1bd 100644
--- a/chart2/qa/extras/chart2dump/chart2dump.cxx
+++ b/chart2/qa/extras/chart2dump/chart2dump.cxx
@@ -32,7 +32,7 @@
 #define DECLARE_DUMP_TEST(TestName, BaseClass, DumpMode) \
     class TestName : public BaseClass { \
         protected:\
-            virtual OUString getTestName() override { return #TestName; } \
+            virtual OUString getTestName() override { return u"" #TestName 
""_ustr; } \
         public:\
             TestName() : BaseClass(DumpMode) {}; \
             CPPUNIT_TEST_SUITE(TestName); \
@@ -46,7 +46,7 @@
 
 #define CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(aActual) \
     if(isInDumpMode()) \
-        writeActual(OUString::number(aActual), #aActual); \
+        writeActual(OUString::number(aActual), u"" #aActual ""_ustr); \
     else \
         { \
             OString sTestFileName = OUStringToOString(getTestFileName(), 
RTL_TEXTENCODING_UTF8); \
@@ -55,7 +55,7 @@
 
 #define CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aActual, EPS_) \
     if(isInDumpMode()) \
-        writeActual(OUString::number(aActual), #aActual); \
+        writeActual(OUString::number(aActual), u"" #aActual ""_ustr); \
         else \
         { \
             OString sTestFileName = OUStringToOString(getTestFileName(), 
RTL_TEXTENCODING_UTF8); \
@@ -64,7 +64,7 @@
 
 #define CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(aActual) \
     if(isInDumpMode()) \
-        writeActual(aActual, #aActual); \
+        writeActual(aActual, u"" #aActual ""_ustr); \
     else \
     { \
         OString sTestFileName = OUStringToOString(getTestFileName(), 
RTL_TEXTENCODING_UTF8); \
@@ -73,7 +73,7 @@
 
 #define CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aActual, EPS_) \
     if(isInDumpMode()) \
-        writeActualTransformation(aActual, #aActual); \
+        writeActualTransformation(aActual, u"" #aActual ""_ustr); \
     else \
     { \
         OUString expectedTransform; \
diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx 
b/connectivity/source/drivers/hsqldb/HDriver.cxx
index 19569dd77d61..234fc969db63 100644
--- a/connectivity/source/drivers/hsqldb/HDriver.cxx
+++ b/connectivity/source/drivers/hsqldb/HDriver.cxx
@@ -213,14 +213,12 @@ namespace connectivity
                 aProperties.put( "JavaDriverClass",
                     OUString(  "org.hsqldb.jdbcDriver"  ) );
                 aProperties.put( "JavaDriverClassPath",
-                    OUString(
 #ifdef SYSTEM_HSQLDB
-                        HSQLDB_JAR
+                        u"" HSQLDB_JAR
 #else
-                        "vnd.sun.star.expand:$LO_JAVA_DIR/hsqldb.jar"
+                        u"vnd.sun.star.expand:$LO_JAVA_DIR/hsqldb.jar"
 #endif
-                        " vnd.sun.star.expand:$LO_JAVA_DIR/sdbc_hsqldb.jar"
-                        ) );
+                        " 
vnd.sun.star.expand:$LO_JAVA_DIR/sdbc_hsqldb.jar"_ustr );
 
                 // auto increment handling
                 aProperties.put( "IsAutoRetrievingEnabled", true );
diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx 
b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
index fbf7abdafb77..4653c0e6174b 100644
--- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
+++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
@@ -60,7 +60,7 @@ using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::accessibility;
 
 #define DEFAULT_QUERY_COLS  20
-#define DEFAULT_SIZE        GetTextWidth("0") * 30
+#define DEFAULT_SIZE        GetTextWidth(u"0"_ustr) * 30
 #define HANDLE_ID            0
 #define HANDLE_COLUMN_WIDTH 70
 #define SORT_COLUMN_NONE    0xFFFFFFFF
diff --git a/i18npool/source/indexentry/indexentrysupplier_default.cxx 
b/i18npool/source/indexentry/indexentrysupplier_default.cxx
index d3f4acb83924..898214f8b1ae 100644
--- a/i18npool/source/indexentry/indexentrysupplier_default.cxx
+++ b/i18npool/source/indexentry/indexentrysupplier_default.cxx
@@ -163,7 +163,7 @@ OUString Index::getIndexDescription(const OUString& 
rIndexEntry)
     return OUString(&indexChar, 1);
 }
 
-#define LOCALE_EN lang::Locale("en", OUString(), OUString())
+#define LOCALE_EN lang::Locale(u"en"_ustr, OUString(), OUString())
 
 void Index::makeIndexKeys(const lang::Locale &rLocale, std::u16string_view 
algorithm)
 {
diff --git a/include/o3tl/nonstaticstring.hxx b/include/o3tl/nonstaticstring.hxx
new file mode 100644
index 000000000000..064134e4d5aa
--- /dev/null
+++ b/include/o3tl/nonstaticstring.hxx
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <string>
+
+#include <rtl/ustrbuf.hxx>
+#include <rtl/ustring.hxx>
+
+namespace o3tl
+{
+// Some test code requires OUString instances that do not have their 
SAL_STRING_STATIC_FLAG set; so
+// they cannot be created from u"..."_ustr literals, but should rather be 
created through this
+// function:
+OUString nonStaticString(std::u16string_view s) { return 
OUStringBuffer(s).makeStringAndClear(); }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/include/oox/core/relations.hxx b/include/oox/core/relations.hxx
index b8a6580648e2..190ae55e419e 100644
--- a/include/oox/core/relations.hxx
+++ b/include/oox/core/relations.hxx
@@ -39,7 +39,7 @@ namespace oox::core {
 /** Expands to an OUString containing an 'officeDocument' strict relation type 
created
     from the passed literal(!) ASCII(!) character array. */
 #define CREATE_OFFICEDOC_RELATION_TYPE_STRICT( ascii ) \
-    ( "http://purl.oclc.org/ooxml/officeDocument/relationships/"; ascii )
+    ( u"http://purl.oclc.org/ooxml/officeDocument/relationships/"; ascii 
""_ustr )
 
 /** Expands to an OUString containing an MS Office specific relation type
     created from the passed literal(!) ASCII(!) character array. */
diff --git a/include/toolkit/helper/macros.hxx 
b/include/toolkit/helper/macros.hxx
index a959acd8792d..fd0cdabca58e 100644
--- a/include/toolkit/helper/macros.hxx
+++ b/include/toolkit/helper/macros.hxx
@@ -152,7 +152,7 @@ void ClassName::MethodName( const EventType& evt ) \
 IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, 
MethodName, EventType )
 
 #define DECLIMPL_SERVICEINFO_DERIVED( ImplName, BaseClass, ServiceName ) \
-    OUString SAL_CALL getImplementationName(  ) override { return 
"stardiv.Toolkit." #ImplName; } \
+    OUString SAL_CALL getImplementationName(  ) override { return 
u"stardiv.Toolkit." #ImplName ""_ustr; } \
     css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() 
override   \
                             { \
                                 css::uno::Sequence< OUString > aNames = 
BaseClass::getSupportedServiceNames( ); \
diff --git a/include/vbahelper/vbahelperinterface.hxx 
b/include/vbahelper/vbahelperinterface.hxx
index 315fcd4f900b..c0aa106329c7 100644
--- a/include/vbahelper/vbahelperinterface.hxx
+++ b/include/vbahelper/vbahelperinterface.hxx
@@ -129,7 +129,7 @@ public:
 #define VBAHELPER_IMPL_XHELPERINTERFACE( classname, servicename ) \
 OUString classname::getServiceImplName() \
 { \
-    return #classname; \
+    return u"" #classname ""_ustr; \
 } \
 css::uno::Sequence< OUString > classname::getServiceNames() \
 { \
diff --git a/sal/qa/rtl/alloc/rtl_alloc.cxx b/sal/qa/rtl/alloc/rtl_alloc.cxx
index cf4813ae16bf..2364f3fe56cf 100644
--- a/sal/qa/rtl/alloc/rtl_alloc.cxx
+++ b/sal/qa/rtl/alloc/rtl_alloc.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <o3tl/nonstaticstring.hxx>
 #include <rtl/alloc.h>
 #include <rtl/ustrbuf.hxx>
 #include <sal/types.h>
@@ -158,7 +159,7 @@ public:
 
         rtl_alloc_preInit(true);
 
-        OUString aFoo("foo"); // [-loplugin:ostr]
+        OUString aFoo(o3tl::nonStaticString(u"foo"));
 
         // fill some cache bits
         for (int iter = 0; iter < 4; iter++)
diff --git a/sax/source/expatwrap/sax_expat.cxx 
b/sax/source/expatwrap/sax_expat.cxx
index 885e2910ba0c..f004b94eadcb 100644
--- a/sax/source/expatwrap/sax_expat.cxx
+++ b/sax/source/expatwrap/sax_expat.cxx
@@ -90,7 +90,7 @@ namespace {
         catch( const css::uno::Exception &e ) {\
             pThis->bExceptionWasThrown = true; \
             pThis->bRTExceptionWasThrown = true; \
-            pImpl->rtexception = WrappedTargetRuntimeException("Non-runtime 
UNO exception caught during parse", e.Context, css::uno::Any(e)); \
+            pImpl->rtexception = WrappedTargetRuntimeException(u"Non-runtime 
UNO exception caught during parse"_ustr, e.Context, css::uno::Any(e)); \
         }\
     }\
     ((void)0)
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index c4ce3fed5a96..1b1cdf90e780 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -54,6 +54,7 @@
 #include <editeng/postitem.hxx>
 #include <editeng/lineitem.hxx>
 
+#include <o3tl/nonstaticstring.hxx>
 #include <svx/svdpage.hxx>
 #include <svx/svdocirc.hxx>
 #include <svx/svdopath.hxx>
@@ -119,11 +120,11 @@ CPPUNIT_TEST_FIXTURE(Test, testSharedStringPool)
     size_t extraCountIgnoreCase = rPool.getCountIgnoreCase();
 
     // Strings that are identical.
-    m_pDoc->SetString(ScAddress(0,0,0), "Andy");  // A1
-    m_pDoc->SetString(ScAddress(0,1,0), "Andy");  // A2
-    m_pDoc->SetString(ScAddress(0,2,0), "Bruce"); // A3
-    m_pDoc->SetString(ScAddress(0,3,0), "andy");  // A4
-    m_pDoc->SetString(ScAddress(0,4,0), "BRUCE"); // A5
+    m_pDoc->SetString(ScAddress(0,0,0), o3tl::nonStaticString(u"Andy"));  // A1
+    m_pDoc->SetString(ScAddress(0,1,0), o3tl::nonStaticString(u"Andy"));  // A2
+    m_pDoc->SetString(ScAddress(0,2,0), o3tl::nonStaticString(u"Bruce")); // A3
+    m_pDoc->SetString(ScAddress(0,3,0), o3tl::nonStaticString(u"andy"));  // A4
+    m_pDoc->SetString(ScAddress(0,4,0), o3tl::nonStaticString(u"BRUCE")); // A5
 
     {
         // These two shared string objects must go out of scope before the 
purge test.
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 3f3f092a5d18..28ef860ba74d 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -27,6 +27,7 @@
 
 #include <math.h>
 
+#include <o3tl/nonstaticstring.hxx>
 #include <svl/numformat.hxx>
 #include <svl/zforlist.hxx>
 #include <svl/zformat.hxx>
@@ -370,9 +371,9 @@ void Test::testSharedStringPoolPurge()
     size_t extraCount = aPool.getCount(); // internal items such as 
SharedString::getEmptyString()
     size_t extraCountIgnoreCase = aPool.getCountIgnoreCase();
 
-    aPool.intern("Andy");
-    aPool.intern("andy");
-    aPool.intern("ANDY");
+    aPool.intern(o3tl::nonStaticString(u"Andy"));
+    aPool.intern(o3tl::nonStaticString(u"andy"));
+    aPool.intern(o3tl::nonStaticString(u"ANDY"));
 
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong string count.", 3+extraCount, 
aPool.getCount());
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong case insensitive string count.", 
1+extraCountIgnoreCase, aPool.getCountIgnoreCase());
@@ -384,10 +385,10 @@ void Test::testSharedStringPoolPurge()
     CPPUNIT_ASSERT_EQUAL(extraCountIgnoreCase, aPool.getCountIgnoreCase());
 
     // Now, create string objects using optional so we can clear them
-    std::optional<svl::SharedString> pStr1 = aPool.intern("Andy");
-    std::optional<svl::SharedString> pStr2 = aPool.intern("andy");
-    std::optional<svl::SharedString> pStr3 = aPool.intern("ANDY");
-    std::optional<svl::SharedString> pStr4 = aPool.intern("Bruce");
+    std::optional<svl::SharedString> pStr1 = 
aPool.intern(o3tl::nonStaticString(u"Andy"));
+    std::optional<svl::SharedString> pStr2 = 
aPool.intern(o3tl::nonStaticString(u"andy"));
+    std::optional<svl::SharedString> pStr3 = 
aPool.intern(o3tl::nonStaticString(u"ANDY"));
+    std::optional<svl::SharedString> pStr4 = 
aPool.intern(o3tl::nonStaticString(u"Bruce"));
 
     CPPUNIT_ASSERT_EQUAL(5+extraCount, aPool.getCount());
     CPPUNIT_ASSERT_EQUAL(2+extraCountIgnoreCase, aPool.getCountIgnoreCase());
@@ -430,8 +431,8 @@ void Test::testSharedStringPoolPurgeBug1()
     svl::SharedStringPool aPool(aSysLocale.GetCharClass());
     size_t extraCount = aPool.getCount(); // internal items such as 
SharedString::getEmptyString()
     size_t extraCountIgnoreCase = aPool.getCountIgnoreCase();
-    aPool.intern("Andy");
-    aPool.intern("andy");
+    aPool.intern(o3tl::nonStaticString(u"Andy"));
+    aPool.intern(o3tl::nonStaticString(u"andy"));
     aPool.purge();
     CPPUNIT_ASSERT_EQUAL(extraCount, aPool.getCount());
     CPPUNIT_ASSERT_EQUAL(extraCountIgnoreCase, aPool.getCountIgnoreCase());
diff --git a/vbahelper/source/vbahelper/vbafontbase.cxx 
b/vbahelper/source/vbahelper/vbafontbase.cxx
index 797fefd5cd7e..23784bb84ca7 100644
--- a/vbahelper/source/vbahelper/vbafontbase.cxx
+++ b/vbahelper/source/vbahelper/vbafontbase.cxx
@@ -30,7 +30,7 @@ using namespace ::com::sun::star;
 
 // form controls use other property name as the remaining OOo API
 #define VBAFONTBASE_PROPNAME( ascii_normal, ascii_control ) \
-    mbFormControl ? OUString( ascii_control ) : OUString( ascii_normal )
+    mbFormControl ? u"" ascii_control ""_ustr : u"" ascii_normal ""_ustr
 
 VbaFontBase::VbaFontBase(
         const uno::Reference< XHelperInterface >& xParent,
diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index 5b8d2a74f462..16d28360f92e 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -114,7 +114,7 @@ class DemoRenderer
         virtual sal_uInt16 getTestRepeatCount() = 0;
 #define RENDER_DETAILS(name,key,repeat) \
         virtual OUString getName() override \
-            { return SAL_STRINGIFY(name); } \
+            { return u"" SAL_STRINGIFY(name) ""_ustr; } \
         virtual sal_uInt16 getAccelerator() override \
             { return key; } \
         virtual sal_uInt16 getTestRepeatCount() override \

Reply via email to