[PATCH] D99005: [clang] Implement P2266 Simpler implicit move
Stephan Bergmann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 14 23:20:19 PDT 2021
sberg added a comment.
(In a build prior to https://reviews.llvm.org/rGc60dd3b2626a4d9eefd9f82f9a406b0d28d3fd72 "Revert '[clang] NRVO: Improvements and handling of more cases.'") I see the following (reduced from https://git.libreoffice.org/core/+/649313625b94e6b879848fc19b607b74375100bf/o3tl/qa/compile-temporary.cxx) started to fail under `-std=c++2b` with this change (and continues to compile fine with `-std=c++20`):
$ cat test.cc
template <typename T> constexpr T& temporary(T&& x) { return x; }
template <typename T> constexpr T& temporary(T&) = delete;
void f(int*);
int g();
void h()
{
f(&temporary(int()));
f(&temporary(g()));
}
$ clang++ -std=c++2b -fsyntax-only test.cc
test.cc:1:62: error: non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'
template <typename T> constexpr T& temporary(T&& x) { return x; }
^
test.cc:7:8: note: in instantiation of function template specialization 'temporary<int>' requested here
f(&temporary(int()));
^
test.cc:8:8: error: no matching function for call to 'temporary'
f(&temporary(g()));
^~~~~~~~~
test.cc:2:36: note: candidate function [with T = int] not viable: expects an lvalue for 1st argument
template <typename T> constexpr T& temporary(T&) = delete;
^
test.cc:1:36: note: candidate template ignored: substitution failure [with T = int]
template <typename T> constexpr T& temporary(T&& x) { return x; }
^
2 errors generated.
It is not clear to me whether that is an intended change in behavior according to http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2266r1.html "Simpler implicit move", or whether it is a bug in this implementation.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99005/new/
https://reviews.llvm.org/D99005
More information about the cfe-commits
mailing list