|
Boost : |
Subject: Re: [boost] [move] Implicit conversion to rvalues and move ctors.
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2014-08-27 19:17:06
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()));
^ ~~~~~~~
In case this helps,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk