summaryrefslogtreecommitdiffstats
path: root/include/com
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-11-10 17:46:57 +0100
committerStephan Bergmann <sbergman@redhat.com>2017-11-11 00:03:37 +0100
commit1fc79c3491906d85ed9972e161112459035b62ed (patch)
tree29f284f4a814b2b7a61417046364b489ce2187d7 /include/com
parentRemove unnecessary makePropertyValue specialization for Any (diff)
downloadcore-1fc79c3491906d85ed9972e161112459035b62ed.tar.gz
core-1fc79c3491906d85ed9972e161112459035b62ed.zip
Avoid using O[U]StringConcat lvalues containing dangling refs to temporaries
...in code accidentally using auto like > auto const aURL = uri->getUriReference() + "/" > + INetURLObject::encode( > m_sEmbeddedName, INetURLObject::PART_FPATH, > INetURLObject::EncodeMechanism::All); > > uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY); in <https://gerrit.libreoffice.org/#/c/44569/1> "Properly construct vnd.sun.star.pkg URL" did (causing hard to debug test failures there). So make functions taking O[U]StringConcat take those by rvalue reference. Unfortunately, that also needed adaption of various functions that just forward their arguments. And some code in sc/qa/unit/ucalc_formula.cxx used CPPUNIT_ASSERT_EQUAL on OUStringConcat arguments in cases where that happened to actually compile (because the structure of the two OUStringConcats was identical), which needed adaption too (but which would arguably better use CPPUNIT_ASSERT_EQUAL_MESSAGE, anyway). Change-Id: I8994d932aaedb2a491c7c81c167e93379d4fb6e3 Reviewed-on: https://gerrit.libreoffice.org/44608 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/com')
-rw-r--r--include/com/sun/star/uno/Any.h4
-rw-r--r--include/com/sun/star/uno/Any.hxx18
2 files changed, 18 insertions, 4 deletions
diff --git a/include/com/sun/star/uno/Any.h b/include/com/sun/star/uno/Any.h
index 93be8c4ce5fd..2e216719b59e 100644
--- a/include/com/sun/star/uno/Any.h
+++ b/include/com/sun/star/uno/Any.h
@@ -79,7 +79,9 @@ public:
#if defined LIBO_INTERNAL_ONLY
template<typename T1, typename T2>
- explicit inline Any(rtl::OUStringConcat<T1, T2> const & value);
+ explicit inline Any(rtl::OUStringConcat<T1, T2> && value);
+ template<typename T1, typename T2>
+ explicit Any(rtl::OUStringConcat<T1, T2> const &) = delete;
#endif
/** Copy constructor: Sets value of the given any.
diff --git a/include/com/sun/star/uno/Any.hxx b/include/com/sun/star/uno/Any.hxx
index 52ca0fc571fe..ac1b43dd779e 100644
--- a/include/com/sun/star/uno/Any.hxx
+++ b/include/com/sun/star/uno/Any.hxx
@@ -26,6 +26,7 @@
#include <cstddef>
#include <iomanip>
#include <ostream>
+#include <utility>
#include "com/sun/star/uno/Any.h"
#include "uno/data.h"
@@ -76,7 +77,8 @@ inline Any::Any( bool value )
#if defined LIBO_INTERNAL_ONLY
template<typename T1, typename T2>
-Any::Any(rtl::OUStringConcat<T1, T2> const & value): Any(rtl::OUString(value))
+Any::Any(rtl::OUStringConcat<T1, T2> && value):
+ Any(rtl::OUString(std::move(value)))
{}
#endif
@@ -239,6 +241,14 @@ template<> Any toAny(Any const & value) { return value; }
#if defined LIBO_INTERNAL_ONLY
+template<typename T1, typename T2>
+Any makeAny(rtl::OUStringConcat<T1, T2> && value)
+{ return Any(std::move(value)); }
+
+template<typename T1, typename T2>
+Any toAny(rtl::OUStringConcat<T1, T2> && value)
+{ return makeAny(std::move(value)); }
+
template<typename T> bool fromAny(Any const & any, T * value) {
assert(value != nullptr);
return any >>= *value;
@@ -275,14 +285,16 @@ inline void SAL_CALL operator <<= ( Any & rAny, bool const & value )
#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
template< class C1, class C2 >
-inline void SAL_CALL operator <<= ( Any & rAny, const rtl::OUStringConcat< C1, C2 >& value )
+inline void SAL_CALL operator <<= ( Any & rAny, rtl::OUStringConcat< C1, C2 >&& value )
{
- const rtl::OUString str( value );
+ const rtl::OUString str( std::move(value) );
const Type & rType = ::cppu::getTypeFavourUnsigned(&str);
::uno_type_any_assign(
&rAny, const_cast< rtl::OUString * >( &str ), rType.getTypeLibType(),
cpp_acquire, cpp_release );
}
+template<typename T1, typename T2>
+void operator <<=(Any &, rtl::OUStringConcat<T1, T2> const &) = delete;
#endif
#if defined LIBO_INTERNAL_ONLY