summaryrefslogtreecommitdiff
path: root/sal/qa
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-03-29 16:28:05 +0200
committerStephan Bergmann <sbergman@redhat.com>2022-03-29 21:15:13 +0200
commitbd94e9dfd0a4c67266e21baa9ec10a56850d093f (patch)
tree2521c85fda5c1765143f146c4259f51568d8e038 /sal/qa
parent2fa01ae540e174452bf5cd763c1464cfe37af076 (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 'sal/qa')
-rw-r--r--sal/qa/rtl/strings/test_ostring_stringliterals.cxx19
-rw-r--r--sal/qa/rtl/strings/test_oustring_stringliterals.cxx16
2 files changed, 35 insertions, 0 deletions
diff --git a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
index e513d56a5d8f..ec0faec94f18 100644
--- a/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_ostring_stringliterals.cxx
@@ -27,6 +27,7 @@ class StringLiterals: public CppUnit::TestFixture
{
private:
void checkCtors();
+ void checkConstexprCtor();
void checkUsage();
void checkNonConstUsage();
void checkBuffer();
@@ -36,8 +37,12 @@ private:
static const char bad5[];
static char bad6[];
+ // Check that OStringLiteral ctor is actually constexpr:
+ static constexpr rtlunittest::OStringLiteral dummy{"dummy"};
+
CPPUNIT_TEST_SUITE(StringLiterals);
CPPUNIT_TEST(checkCtors);
+CPPUNIT_TEST(checkConstexprCtor);
CPPUNIT_TEST(checkUsage);
CPPUNIT_TEST(checkNonConstUsage);
CPPUNIT_TEST(checkBuffer);
@@ -110,6 +115,20 @@ void test::ostring::StringLiterals::testcall( const char str[] )
#endif
}
+void test::ostring::StringLiterals::checkConstexprCtor()
+{
+#if __cplusplus >= 202002L
+ static constinit
+#endif
+ rtl::OString s(dummy);
+ CPPUNIT_ASSERT_EQUAL(oslInterlockedCount(0x40000000), s.pData->refCount);
+ // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
+ CPPUNIT_ASSERT_EQUAL(rtl::OString("dummy"), s);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<void const *>(dummy.getStr()), static_cast<void const *>(s.getStr()));
+}
+
void test::ostring::StringLiterals::checkUsage()
{
// simply check that all string literal based calls work as expected
diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
index 9227cac84e7e..0caa3fc03579 100644
--- a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
@@ -34,6 +34,7 @@ class StringLiterals: public CppUnit::TestFixture
{
private:
void checkCtors();
+ void checkConstexprCtor();
void checkUsage();
void checkBuffer();
void checkOUStringLiteral();
@@ -48,6 +49,7 @@ private:
CPPUNIT_TEST_SUITE(StringLiterals);
CPPUNIT_TEST(checkCtors);
+CPPUNIT_TEST(checkConstexprCtor);
CPPUNIT_TEST(checkUsage);
CPPUNIT_TEST(checkBuffer);
CPPUNIT_TEST(checkOUStringLiteral);
@@ -118,6 +120,20 @@ void test::oustring::StringLiterals::testcall( const char str[] )
!VALID_CONVERSION_CALL([&str]() { return rtl::OUString(str); }));
}
+void test::oustring::StringLiterals::checkConstexprCtor()
+{
+#if __cplusplus >= 202002L
+ static constinit
+#endif
+ rtl::OUString s(dummy);
+ CPPUNIT_ASSERT_EQUAL(oslInterlockedCount(0x40000000), s.pData->refCount);
+ // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), s.getLength());
+ CPPUNIT_ASSERT_EQUAL(rtl::OUString("dummy"), s);
+ CPPUNIT_ASSERT_EQUAL(
+ static_cast<void const *>(dummy.getStr()), static_cast<void const *>(s.getStr()));
+}
+
void test::oustring::StringLiterals::checkUsage()
{
// simply check that all string literal based calls work as expected