Quuxplusone added a comment.

@sberg: Thanks for the example! @mizvekov's comments are correct, but I wanted 
to put some more comments here for posterity. (I'll also try to find a place 
for this real-world example in the next revision of p2266 
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2266r1.html>.)

The code in question is `o3tl::temporary`, documented as "Cast an rvalue to an 
lvalue." and implemented as `template<class T> T& temporary(T&& x) { return x; 
}`
https://docs.libreoffice.org/o3tl/html/temporary_8hxx_source.html
p2266 proposes to break this code in C++23, by making the expression `x` an 
xvalue. EWG was well aware that p2266 would break this exact kind of 
"laundering" function, which takes an rvalue and launders it into an lvalue 
without a cast. This breakage was generally (though I'm sure not universally) 
seen as a good thing. We weren't aware of any specific real-world examples of 
such "laundering" functions, though, so this is very useful info.
As Matheus says, the best way to fix the code is to add an explicit cast: 
`return static_cast<T&>(x);`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99005/new/

https://reviews.llvm.org/D99005

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to