Boost logo

Boost :

Subject: Re: [boost] [move] Implicit conversion to rvalues and move ctors.
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2014-08-27 19:49:59


On Wed, 27 Aug 2014 16:17:06 -0700, Vicente J. Botet Escriba
<vicente.botet_at_[hidden]> wrote:

> Le 26/08/14 02:59, Mostafa a écrit :
>> Here's another use case that fails to compile in C++03 but compiles
>> successfully in C++11. (Note, it fails to compile in VS2005 and g++
>> 4.8.2 -std=c++98, and compiles successfully with g++ 4.8.2 -std=c++11)
>>
>> MOC is a BOOST_MOVABLE_BUT_NOT_COPYABLE type. Foo is an empty with an
>> implicit conversion function to MOC. "MOC m(Foo());" compiles
>> successfully but "MOC m2(makeFoo());" fails to compile. Is this a bug
>> or a limitation of Boost.Move in C++03?
>>
>> //----------
>> //Start Code
>> //----------
>>
>> #include <boost/move/core.hpp>
>> #include <boost/move/utility.hpp>
>>
>> struct MOC
>> {
>> MOC() : value(121) {}
>> MOC(BOOST_RV_REF(MOC) rhs) : value(rhs.value) {}
>> int value;
>> private:
>> BOOST_MOVABLE_BUT_NOT_COPYABLE(MOC)
>> };
>>
>> struct Foo
>> {
>> operator MOC ()
>> {
>> return MOC();
>> }
>> };
>>
>> Foo makeFoo()
>> {
>> return Foo();
>> }
>>
>> int main()
>> {
>> // (1) Successfully Compiles.
>> MOC m(Foo());
>>
>> // (2) Fails to Compile.
>> MOC m2(makeFoo());
>>
>> return 0;
>> }
>>
> I'm getting
>
> ../example/lambda_future.cpp:32:8: warning: parentheses were
> disambiguated as a function declaration [-Wvexing-parse]
> MOC m(Foo());
> ^~~~~~~
> ../example/lambda_future.cpp:32:9: note: add a pair of parentheses to
> declare a variable
> MOC m(Foo());
> ^
> ( )
>
>
>
> After adding the parentheses I get
> ../example/lambda_future.cpp:32:7: error: no matching constructor for
> initialization of 'MOC'
> MOC m((Foo()));
> ^ ~~~~~~~

Yes, you're right. That would explain the different compiler behaviors
between (1) and (2). Adding double parenthesis to both (1) and (2) now
gives me the same error messages in g++ 4.8.2 -std=c++98. But they both do
compile under C++11 mode. FWIW, I have an internal workaround, I'm just
wondering if this is another undocumented limitation of Boost.Move in
C++98.

(What's strange is that on my machine -Wall -pedantic doesn't even catch
that MVPE you noted above.)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk