diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2023-03-16 11:52:29 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2023-03-17 14:52:05 +0000 |
commit | b8f131d4cc0454ffe4f809763ce6bccafeab3eb0 (patch) | |
tree | 840eabca87e4a0c902e9acf257c87019ee2569f4 /include/rtl | |
parent | 796c9c5ac2196e62546bcef229dcd08a3b8724db (diff) |
Towards literal O[U]String types in C++20
...(where destructors can be constexpr), making
21584b304b21bfe6b99b6f29018c6b754ea28fc0 "make OUString(OUStringLiteral)
constructor constexpr" and 983c1146ac80c038feae653e8e3752a72171d6cb "actually
make OString(OStringLiteral) constructor constexpr" actually useful and
eventually removing the need for O[U]StringConstExpr again
Change-Id: I55520c1d928758f61e92336206e0f14b6f12a711
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148978
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/rtl')
-rw-r--r-- | include/rtl/string.hxx | 15 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 15 |
2 files changed, 28 insertions, 2 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index 0a90fc9f04a3..6af1a1a3b339 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -452,9 +452,22 @@ public: /** Release the string data. */ +#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L + constexpr +#endif ~OString() { - rtl_string_release( pData ); +#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L + 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. + } else +#endif + rtl_string_release( pData ); } #if defined LIBO_INTERNAL_ONLY diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index f8b5fb461d2f..008f820bb3b1 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -521,9 +521,22 @@ public: /** Release the string data. */ +#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L + constexpr +#endif ~OUString() { - rtl_uString_release( pData ); +#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L + 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. + } else +#endif + rtl_uString_release( pData ); } /** Provides an OUString const & passing a storage pointer of an |