If you do not want to allow double-move for certain code in the future, better use relocation (according to one of the proposals, whatever is accepted) there.


For those the object is not meant to be used afterwards and the compiler could (if it is detectable) abort with an error.


So it would be better fitting to your proposal to build on relocation.


-----Ursprüngliche Nachricht-----
Von: Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Fr 23.06.2023 09:34
Betreff: Re: [std-proposals] Force compilers to warn about double moves
An: std-proposals@lists.isocpp.org;
CC: Frederick Virchanza Gotham <cauldwell.thomas@gmail.com>;
On Thu, Jun 22, 2023 at 6:17 PM Hyman Rosen via Std-Proposals
<std-proposals@lists.isocpp.org> wrote:
> It may also be reasonable for someone to do
> void F(C &&o) {
>     A_MightTake(move(o));
>     B_MightTake(move(o));
>     ...
> }
> to let a sequence of functions examine an object
> and maybe take it, maybe not.  First one that
> wants it, gets it, the rest see a moved-from
> empty object.

Okay then how about my proposed compiler warning/error only kicks in
when then Rvalue reference is marked with postfix '&&'   ?

So the following would fail to compile:

   void F(C &&o&&)
       A_MightTake( o );
       B_MightTake( o );  // possible double-move

And in order to alleviate this error, you would abandon the use of the
postfix '&&' operator, and you would simply mark the function
parameter as "&&o" instead of "&&o&&", and use 'std::move' as normal.

By the way, when it comes to marking a function parameter with both
prefix and postfix '&&', it would have no effect in a function
declaration, i.e. the following two function signatures are

   void F(C &&o);
   void F(C &&o&&);

There would be a difference however in the function definition as follows:

   void F(C &&o&&)
       // In here, 'o' is always an R-value (no need for 'move' or 'forward')

So if you decide to change a function parameter from "&&o" to "&&o&&",
then none of the header files need to change.
Std-Proposals mailing list