C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Force compilers to warn about double moves

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 22 Jun 2023 08:39:21 -0700
On Thursday, 22 June 2023 06:30:05 PDT Frederick Virchanza Gotham via Std-
Proposals wrote:
> Make it compulsory for a compiler to issue a diagnostic (and possibly
> also terminate compilation) in the following scenario:
>
> void Func(SomeClass &&obj)
> {
> SomeOtherFunc( move(obj) );
>
> AndAgainSomeOtherFunction( move(obj) );
> }

clang-tidy already issues this warning. I see no reason why a compiler
couldn't do it too. This means it's QoI, so please open a request with your
vendor for them to do it.

The code above is NOT ill-formed and there's nothing the standard can do to
enforce. The classes in question could abuse rvalue mechanisms to store an
output value in "obj" which can be passed from object to object.


-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-06-22 15:39:24