summaryrefslogtreecommitdiff
path: root/include/o3tl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2021-06-16 15:59:24 +0200
committerStephan Bergmann <sbergman@redhat.com>2021-06-17 14:16:59 +0200
commit21da7d80aa1ee0f9661dcde37bc4629d5eb9d50e (patch)
tree72f89372b9a24fbab862646c0751f0d137807ef8 /include/o3tl
parent12ad78492e06cfece2b166ed67630f30a439b452 (diff)
Adapt o3tl::temporary to C++23 P2266R1
With the recent implemenation of <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2266r1.html> "P2266R1: Simpler implicit move" in Clang 13 trunk as <https://github.com/llvm/llvm-project/commit/bf20631782183cd19e0bb7219e908c2bbb01a75f> "[clang] Implement P2266 Simpler implicit move", a --with-latest-c++ build started to fail with > In file included from sal/rtl/random.cxx:25: > include/o3tl/temporary.hxx:21:62: error: non-const lvalue reference to type 'double' cannot bind to a temporary of type 'double' > template <typename T> constexpr T& temporary(T&& x) { return x; } > ^ > sal/rtl/random.cxx:97:37: note: in instantiation of function template specialization 'o3tl::temporary<double>' requested here > return std::modf(random, &o3tl::temporary(double())); > ^ etc. (And fixing that by adding the recommended static_cast then triggered a false loplugin:redundantcast warning.) Change-Id: I222429e9872afdedf77a07014c0a2e9e06c60b50 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117335 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/o3tl')
-rw-r--r--include/o3tl/temporary.hxx2
1 files changed, 1 insertions, 1 deletions
diff --git a/include/o3tl/temporary.hxx b/include/o3tl/temporary.hxx
index 7b6c9a1f9fc7..50d006e26d0e 100644
--- a/include/o3tl/temporary.hxx
+++ b/include/o3tl/temporary.hxx
@@ -18,7 +18,7 @@ namespace o3tl
// and some call site doesn't need the value beyond the call itself (e.g., in a call like
// std::modf(x, &o3tl::temporary(double())) to obtain the fractional part of x, ignoring the
// integral part).
-template <typename T> constexpr T& temporary(T&& x) { return x; }
+template <typename T> constexpr T& temporary(T&& x) { return static_cast<T&>(x); }
template <typename T> constexpr T& temporary(T&) = delete;
}