I am trying this code in Visual Studio 2015 v4.
using namespace std;
void * operator new(size_t size) {
cout << "Creating new " << endl;
void * p = malloc(size);
return p;
}
class CTest {
private:
string a;
string b;
public:
CTest( const string &&one , const string && two ) :a(move(one)), b(move(two)) {}
};
int main() {
CTest("one", "one" );
return 0;
}
This code outputs "Creating new" 4 times in Visual studio , which means it allocates memory 4 times. However following semantics it should only allocate twice ( creating 2 literals in data segment , creating one and two function argument = 2 allocs , and then moving their resource to a and b member variable )
Compiling this under g++ outputs "Creating new" twice, as it should.
Is there any settings i need to set in order for VS to follow moving semantics? It should be supported by default as far as i know.
Thanks for help.