|
Boost : |
Subject: Re: [boost] [move] problem with msvc and BOOST_MOVABLE_BUT_NOT_COPYABLE
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2010-05-28 14:13:48
On 28/05/2010 19:32, Thomas Klimpel wrote:
> The expectation that the statement "return x;" will benefit from RVO
might not be justified here. Writing "return boost::move(x);" might
actually be a good idea.
GCC 4.4.1 with -std=gnu++0x behaves similarly to boost.move emulation:
volatile int cond = 0;
class X
{
X(const X&);
X& operator=(const X&);
public:
X(){}
X(X&&){}
X& operator=(X&&){}
static X create()
{
X x, x2;
return cond ? x : x2; // passing value form static member-fn
}
};
int main()
{
X x(X::create());
return 0;
}
$ gcc test.cpp -std=gnu++0x
C:\Users\IGAZTA~1\AppData\Local\Temp\ccUoS3Ag.o:test.cpp:(.text$_ZN1X6createEv[X::create()]+0x46):
undefined reference to `X::X(X const&)'
collect2: ld returned 1 exit status
Same with MSVC-10.0:
1>------ Build started: Project: test, Configuration: Debug Win32 ------
1> test.cpp
1>test.obj : error LNK2001: unresolved external symbol "private:
__thiscall X::X(class X const &)" (??0X@@AAE_at_ABV0@@Z)
1>c:\users\igaztanaga\documents\visual studio
2010\Projects\test\Debug\test.exe : fatal error LNK1120: 1 unresolved
externals
But I would expect a compile-time error. All fine if we change the
return statement to:
return cond ? static_cast<X&&>(x) : static_cast<X&&>(x2);
Best,
Ion
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk