idl/source/cmptools/lex.cxx |   16 ++++++++++++++++
 include/rtl/string.hxx      |   12 ++++++++++++
 include/rtl/ustring.hxx     |   11 ++++++++++-
 3 files changed, 38 insertions(+), 1 deletion(-)

New commits:
commit 37db2eaa1dea6cd4468754e7bb80e1b0c1bb6d8c
Author:     Stephan Bergmann <[email protected]>
AuthorDate: Wed Jul 23 16:18:48 2025 +0200
Commit:     Stephan Bergmann <[email protected]>
CommitDate: Thu Jul 24 17:13:37 2025 +0200

    Make O[U]String default ctors constexpr
    
    (with the same caveats for MSVC /clr code as discussed in
    5a40abc86b94c0be5b4a252c6ab5b0b0df6e520d "Drop some newly obsolete 
__cplusplus
    version checks")
    
    Change-Id: I080a37029479155ec4135732c4d5dd0caba4f5dc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188236
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <[email protected]>

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 43a31e92303a..a39f08dbb4aa 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -199,10 +199,17 @@ public:
     /**
       New string containing no characters.
     */
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
+    constexpr
+#endif
     OString()
     {
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
+        pData = const_cast<rtl_String *>(&empty.str);
+#else
         pData = NULL;
         rtl_string_new( &pData );
+#endif
     }
 
     /**
@@ -2607,6 +2614,11 @@ public:
     OStringConcat<OStringConcatMarker, T[N]>
     Concat(T (& value)[N]) { return OStringConcat<OStringConcatMarker, 
T[N]>(value); }
 #endif
+
+private:
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
+        static constexpr auto empty = OStringLiteral(""); // [-loplugin:ostr]
+#endif
 };
 
 #if defined LIBO_INTERNAL_ONLY
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index b03978c7d625..99cd213f2a76 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -178,12 +178,18 @@ public:
     /**
       New string containing no characters.
     */
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
+    constexpr
+#endif
     OUString()
     {
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
+        pData = const_cast<rtl_uString *>(&empty.str);
+#else
         pData = NULL;
         rtl_uString_new( &pData );
+#endif
     }
-
     /**
       New string from OUString.
 
@@ -3751,6 +3757,9 @@ private:
         return *this;
     }
 
+#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && 
defined _MANAGED)
+    static constexpr auto empty = OUStringLiteral(u""); // [-loplugin:ostr]
+#endif
 };
 
 #if defined LIBO_INTERNAL_ONLY
commit 5add8fd40446796777c90a143dfa96f3fd22eed9
Author:     Stephan Bergmann <[email protected]>
AuthorDate: Wed Jul 23 22:40:03 2025 +0200
Commit:     Stephan Bergmann <[email protected]>
CommitDate: Thu Jul 24 17:13:29 2025 +0200

    Silence bogus GCC -Wmaybe-uninitialized
    
    > In file included from idl/source/cmptools/lex.cxx:22:
    > In member function ‘SvToken& SvToken::operator=(const SvToken&)’,
    >     inlined from ‘void SvTokenStream::FillTokenList()’ at 
idl/source/cmptools/lex.cxx:92:35:
    > idl/inc/lex.hxx:35:7: error: ‘<anonymous>.SvToken::<anonymous>’ may be 
used uninitialized [-Werror=maybe-uninitialized]
    >    35 | class SvToken
    >       |       ^~~~~~~
    > idl/source/cmptools/lex.cxx: In member function ‘void 
SvTokenStream::FillTokenList()’:
    > idl/source/cmptools/lex.cxx:92:35: note: ‘<anonymous>’ declared here
    >    92 |                 *pToken = SvToken();
    >       |                                   ^
    > In member function ‘SvToken& SvToken::operator=(const SvToken&)’,
    >     inlined from ‘void SvTokenStream::FillTokenList()’ at 
idl/source/cmptools/lex.cxx:101:31:
    > idl/inc/lex.hxx:35:7: error: ‘<anonymous>.SvToken::<anonymous>’ may be 
used uninitialized [-Werror=maybe-uninitialized]
    >    35 | class SvToken
    >       |       ^~~~~~~
    > idl/source/cmptools/lex.cxx: In member function ‘void 
SvTokenStream::FillTokenList()’:
    > idl/source/cmptools/lex.cxx:101:31: note: ‘<anonymous>’ declared here
    >   101 |             *pToken = SvToken();
    >       |                               ^
    
    seen in optimizing LO builds using at least GCC 12
    (<https://ci.libreoffice.org/job/gerrit_linux_gcc_release/192633/>) and GCC 
15
    (locally, gcc-15.1.1-2.fc42.x86_64) after upcoming
    <https://gerrit.libreoffice.org/c/core/+/188236> "Make O[U]String default 
ctors
    constexpr".
    
    (And without adding the additional braces in the second code block, at 
least GCC
    15 would emit an odd
    
    > idl/source/cmptools/lex.cxx: In member function ‘void 
SvTokenStream::FillTokenList()’:
    > idl/source/cmptools/lex.cxx:116:9: error: ‘else’ without a previous ‘if’
    >   116 |         else if( pToken->IsEof() )
    >       |         ^~~~
    
    )
    
    Change-Id: I171c746ea3f6035bc737b4bcd636dd063dd9186e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188265
    Reviewed-by: Stephan Bergmann <[email protected]>
    Tested-by: Jenkins

diff --git a/idl/source/cmptools/lex.cxx b/idl/source/cmptools/lex.cxx
index 52f292084d94..e81821f3750f 100644
--- a/idl/source/cmptools/lex.cxx
+++ b/idl/source/cmptools/lex.cxx
@@ -89,7 +89,14 @@ void SvTokenStream::FillTokenList()
         {
             if (!aTokList.empty())
             {
+#if defined __GNUC__ && !defined __clang__ && __GNUC__ >= 12 && __GNUC__ <= 15
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
                 *pToken = SvToken();
+#if defined __GNUC__ && !defined __clang__ && __GNUC__ >= 12 && __GNUC__ <= 15
+#pragma GCC diagnostic pop
+#endif
                 std::vector<std::unique_ptr<SvToken> >::const_iterator it = 
aTokList.begin();
 
                 pToken->SetLine((*it)->GetLine());
@@ -98,7 +105,16 @@ void SvTokenStream::FillTokenList()
             break;
         }
         else if( pToken->IsComment() )
+        {
+#if defined __GNUC__ && !defined __clang__ && __GNUC__ >= 12 && __GNUC__ <= 15
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
             *pToken = SvToken();
+#if defined __GNUC__ && !defined __clang__ && __GNUC__ >= 12 && __GNUC__ <= 15
+#pragma GCC diagnostic pop
+#endif
+        }
         else if( pToken->IsEof() )
             break;
         else

Reply via email to