From b8f131d4cc0454ffe4f809763ce6bccafeab3eb0 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 16 Mar 2023 11:52:29 +0100 Subject: 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 --- include/rtl/string.hxx | 15 ++++++++++++++- include/rtl/ustring.hxx | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'include/rtl') 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 -- cgit