When I did the fast string concatenation, I didn't add any support for number(), which simply returned a O(U)String, and so it did the extra allocation/deallocation, although that could be avoided. In order to support this, number() now returns a special temporary return type, similarly to O(U)StringConcat, which allows delaying the concatenation the same way. Also similarly, the change of the return type in some cases requires explicit cast to the actual string type. Usage of OString::getStr() is so extensive in the codebase that I actually added it to the helper class, after that it's only relatively few cases. Change-Id: Iba6e158010e1e458089698c426803052b6f46031 Reviewed-on: https://gerrit.libreoffice.org/78873 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
68 lines
2.3 KiB
C++
68 lines
2.3 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* Based on LLVM/Clang.
|
|
*
|
|
* This file is distributed under the University of Illinois Open Source
|
|
* License. See LICENSE.TXT for details.
|
|
*
|
|
*/
|
|
|
|
#include <rtl/ustring.hxx>
|
|
|
|
void foo()
|
|
{
|
|
auto str1 = "str1" + OUString::number( 10 );
|
|
// expected-error-re@-1 {{creating a variable of type 'rtl::OUStringConcat<{{.*}}>' will make it reference temporaries}}
|
|
// expected-note@-2 {{use OUString instead}}
|
|
OUString str2 = "str2" + OUString::number( 20 ) + "ing";
|
|
const auto& str3 = "str3" + OUString::number( 30 );
|
|
// expected-error-re@-1 {{creating a variable of type 'const rtl::OUStringConcat<{{.*}}> &' will make it reference temporaries}}
|
|
// expected-note@-2 {{use OUString instead}}
|
|
const auto str4 = "str4" + OString::number( 40 );
|
|
// expected-error-re@-1 {{creating a variable of type 'const rtl::OStringConcat<{{.*}}>' will make it reference temporaries}}
|
|
// expected-note@-2 {{use OString instead}}
|
|
auto str5 = OUString::number( 50 );
|
|
// expected-error-re@-1 {{creating a variable of type 'rtl::OUStringNumber<{{.*}}>' will make it reference temporaries}}
|
|
// expected-note@-2 {{use OUString instead}}
|
|
(void) str1;
|
|
(void) str2;
|
|
(void) str3;
|
|
(void) str4;
|
|
(void) str5;
|
|
}
|
|
|
|
struct A
|
|
{
|
|
auto bar()
|
|
// expected-error-re@-1 {{returning a variable of type 'rtl::OStringConcat<{{.*}}>' will make it reference temporaries}}
|
|
// expected-note@-2 {{use OString instead}}
|
|
{
|
|
return "bar" + OString::number( 110 );
|
|
}
|
|
auto baz()
|
|
// expected-error-re@-1 {{returning a variable of type 'rtl::OStringNumber<{{.*}}>' will make it reference temporaries}}
|
|
// expected-note@-2 {{use OString instead}}
|
|
{
|
|
return OString::number( 120 );
|
|
}
|
|
};
|
|
|
|
template< typename T >
|
|
void fun( const T& par )
|
|
// parameters are without warnings
|
|
{
|
|
const T& var = par;
|
|
// expected-error-re@-1 {{creating a variable of type 'const rtl::OUStringConcat<{{.*}}> &' will make it reference temporaries}}
|
|
// expected-note@-2 {{use OUString instead}}
|
|
(void) var;
|
|
}
|
|
|
|
void testfun()
|
|
{
|
|
fun( "fun" + OUString::number( 200 ));
|
|
}
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|