diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2023-10-17 23:40:05 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2023-10-18 07:36:40 +0200 |
commit | c7cef7500105c6122df90900b3ba919e80c3bbb9 (patch) | |
tree | f67bbe5296bc58ef89d3e034899459157b14345e /include | |
parent | 6320a4c21cf54d32c778417ee077d67fd0bad050 (diff) |
O[U]String move ctors should be constexpr, too
...similar to 5f2206e3ccf1cf64d2b11b0e5d419973269920a8 "O{U]String copy ctor
should be constexpr", which will again be useful for some upcoming replacements
of OUStringConstExpr with OUString, and making data actually constexpr. (For
example, the
static o3tl::enumarray<INetProtocol, SchemeInfo> const map
in INetURLObject::getSchemeInfo (tools/source/fsys/urlobj.cxx) can actually be
constexpr, but the o3tl::enumarray ctor forwards its SchemeInfo arguments by
forwarding references, so uses an implicitly generated constexpr SchemeInfo move
ctor, which in turn requires constexpr member move ctors. So when the m_sScheme
member will be changed from rtl::OUStringConstExpr to OUString, the OUString
move ctor better be constexpr.)
Change-Id: Icfc5edbb8422919186517667f876ea90bec1be90
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158099
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/rtl/string.hxx | 14 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 14 |
2 files changed, 28 insertions, 0 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index de468f127757..a2be12ab320d 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -240,9 +240,23 @@ public: @param str an OString. @since LibreOffice 5.2 */ +#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED) + constexpr +#endif OString( OString && str ) noexcept { pData = str.pData; +#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED) + if (std::is_constant_evaluated()) { + //TODO: We would want to + // + // assert(SAL_STRING_IS_STATIC(pData)); + // + // here, but that wouldn't work because read of member `str` of OUStringLiteral's + // anonymous union with active member `more` is not allowed in a constant expression. + return; + } +#endif str.pData = nullptr; rtl_string_new( &str.pData ); } diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index 8e8bd8e9580e..a88c2a303194 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -250,9 +250,23 @@ public: @param str an OUString. @since LibreOffice 5.2 */ +#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED) + constexpr +#endif OUString( OUString && str ) noexcept { pData = str.pData; +#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED) + if (std::is_constant_evaluated()) { + //TODO: We would want to + // + // assert(SAL_STRING_IS_STATIC(pData)); + // + // here, but that wouldn't work because read of member `str` of OUStringLiteral's + // anonymous union with active member `more` is not allowed in a constant expression. + return; + } +#endif str.pData = nullptr; rtl_uString_new( &str.pData ); } |