Код: Выделить всё
struct TestCase
{
TestCase() {}
TestCase(const TestCase&) = delete;
TestCase(TestCase&&) {}
TestCase& operator=(const TestCase&) = delete;
TestCase& operator=(TestCase&&) { return *this; }
};
TestCase funcReturningOnlyMovableType()
{
TestCase test_case;
TestCase* ptr_test_case = &test_case;
TestCase& ref_to_test_case = test_case;
return test_case; // WORKS
//return *ptr_test_case; // DOESN'T WORK COPY CONSTRUCTOR IS DELETED
//return ref_to_test_case; // DOESN'T WORK COPY CONSTRUCTOR IS DELETED
}
int main()
{
TestCase test_case = funcReturningOnlyMovableType();
}
Это случилось со мной в MSVC, но с тех пор я проверил Compiler Explorer, и то же самое происходит в GCC и Clang.
Подробнее здесь: https://stackoverflow.com/questions/791 ... rning-a-po
Мобильная версия