struct Test
{
Test()
{}
Test(const Test& other)
{
cout << "Copy" << endl;
}
Test(Test&& other)
{
cout << "Move" << endl;
}
};
Test* f()
{
static Test t;
return &t;
}
int main()
{
auto t = *f();
return 0;
}
出力:コピー
*f()
は明らかに匿名の一時オブジェクトであるため、r 値である必要があり、move-constructor を呼び出す必要があります。コンパイラが左辺値として扱うのはなぜ*f()
ですか?
コンパイラのバグなのか、私の理解が間違っているのでしょうか。