Is it possible to return an instance of a non-movable, non-copyable type?

后端 未结 3 1711
长发绾君心
长发绾君心 2021-02-12 19:55

In VS2013 update 5, I\'ve got this:

class Lock
{
public:
    Lock(CriticalSection& cs) : cs_(cs)
    {}

    Lock(const Lock&) = delete;
    Lock(Lock&am         


        
3条回答
  •  梦谈多话
    2021-02-12 20:56

    As of MSVC v19.14, MSVC (aka Visual Studio) also implements the C++17 behavior of allowing return of a non-copyable, non-movable object in cases where the RVO applies: https://godbolt.org/z/fgUFdf

    As rubenvb's answer indicates, this means that GCC, Clang, and MSVC all support this C++17 behavior: https://godbolt.org/z/Hq_GyG

提交回复
热议问题