Kaydet (Commit) f0fcbcad authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Make OUStringLiteral ctor actually constexpr

...which had accidentally been broken with
87707670 "Make OUStringLiteral more useful".
(std::strlen unfortunately isn't constexpr, so need to use an explicit loop
instead.)

Change-Id: I9a820e2940b99a0c37124477810ef879d82c8325
Reviewed-on: https://gerrit.libreoffice.org/59344
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 7d01ce40
......@@ -13,10 +13,13 @@
#include "sal/config.h"
#include <cstddef>
#include <cstring>
#include "sal/types.h"
#if defined LIBO_INTERNAL_ONLY
#include "config_global.h"
#endif
// The unittest uses slightly different code to help check that the proper
// calls are made. The class is put into a different namespace to make
// sure the compiler generates a different (if generating also non-inline)
......@@ -165,8 +168,20 @@ struct ConstCharArrayDetector< const char[ N ], T >
typedef T Type;
static const std::size_t length = N - 1;
static const bool ok = true;
static bool isValid(char const (& literal)[N])
{ return std::strlen(literal) == length; }
#if defined LIBO_INTERNAL_ONLY && HAVE_CXX14_CONSTEXPR
constexpr
#endif
static bool isValid(char const (& literal)[N]) {
for (std::size_t i = 0; i != N - 1; ++i) {
if (literal[i] == '\0') {
return false;
}
}
return literal[N - 1] == '\0';
}
#if defined LIBO_INTERNAL_ONLY
constexpr
#endif
static char const * toPointer(char const (& literal)[N]) { return literal; }
};
#if defined LIBO_INTERNAL_ONLY
......
......@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <algorithm>
#include <cstring>
#include <osl/nlsupport.h>
#include <osl/diagnose.h>
......
......@@ -41,6 +41,9 @@ private:
void testcall( const char str[] );
// Check that OUStringLiteral ctor is actually constexpr:
static constexpr rtlunittest::OUStringLiteral dummy{"dummy"};
CPPUNIT_TEST_SUITE(StringLiterals);
CPPUNIT_TEST(checkCtors);
CPPUNIT_TEST(checkUsage);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment