[cfe-dev] [libc++]x=move(x) behavior
chen xu via cfe-dev
cfe-dev at lists.llvm.org
Thu Oct 1 15:28:22 PDT 2015
Hi, my project code (linux, Clang as compiler and LLVM libcxx as c++ library) will have the execution of x=std::move(x) in some code path (not directly, but sometimes it will happen via levels of function calls and parameter-pass by reference, etc.), and it turns out x is cleared after this x = std::move(x). I tried gnu c++ library, and msvc c++ library (on windows), both keep x untouched.
I am wondering if this could be fixed in LLVM libcxx, as it seems making more sense not to clear x when moving x to itself. Thanks. Below is a sample code for repro. Thanks a lot.
#include <iostream>using namespace std;
class Test {
public:
Test() :
x("test") { }
void MoveX() {
cout << "before x=move(x), x : " << x;
x=move(x);
cout << "after x=move(x), x : " << x; }private:
string x;
};
int main(int argc, char** argv){ Test test; test.MoveX(); return 0;}
The output would be like
before x=move(x), x : testafter x=move(x), x :
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151001/f53f9a5d/attachment.html>
More information about the cfe-dev
mailing list