diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2022-03-29 16:28:05 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2022-03-29 21:15:13 +0200 |
commit | bd94e9dfd0a4c67266e21baa9ec10a56850d093f (patch) | |
tree | 2521c85fda5c1765143f146c4259f51568d8e038 /include/rtl | |
parent | 2fa01ae540e174452bf5cd763c1464cfe37af076 (diff) |
Add back the opportunity to leave O[U]StringLiteral's buffer uninitialized
...once we have a C++20 baseline, which would render uses of the consteval
O[U]StringLiteral ctors ill-formed if we accidentally failed to write to all of
buffer's elements. This had been broken (and the TODO comments had become
misleading) with 21584b304b21bfe6b99b6f29018c6b754ea28fc0 "make
OUString(OUStringLiteral) constructor constexpr" and
bca539e889d40e06cb3275442622cb075b2484a2 "make OString(OStringLiteral)
constructor constexpr".
Also add corresponding test code.
Change-Id: I2bc680282c717d403a681ff4b9396580c8382de1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132275
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/rtl')
-rw-r--r-- | include/rtl/string.hxx | 19 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 19 |
2 files changed, 18 insertions, 20 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index 440f80900855..e99581cd6f94 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -135,18 +135,17 @@ private: static_assert(offsetof(OStringLiteral, str.buffer) == offsetof(OStringLiteral, more.buffer)); } + struct Data { + Data() = default; + + oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx) + sal_Int32 length = N - 1; + char buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2) + }; + union { rtl_String str; - struct { - oslInterlockedCount refCount; - sal_Int32 length; - char buffer[N]; - } more = - { - 0x40000000, // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx) - N - 1, - {} //TODO: drop initialization for C++20 (P1331R2) - }; + Data more = {}; }; }; #endif diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index 4d983a089f72..1a6a1cae8990 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -117,18 +117,17 @@ private: static_assert(offsetof(OUStringLiteral, str.buffer) == offsetof(OUStringLiteral, more.buffer)); } + struct Data { + Data() = default; + + oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx) + sal_Int32 length = N - 1; + sal_Unicode buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2) + }; + union { rtl_uString str; - struct { - oslInterlockedCount refCount; - sal_Int32 length; - sal_Unicode buffer[N]; - } more = - { - 0x40000000, // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx) - N - 1, - {} //TODO: drop initialization for C++20 (P1331R2) - }; + Data more = {}; }; }; |