title: Is it possible to return an instance of a non-movable, non-copyable type?
body: <p>In VS2013 update 5, I've got this:</p>
  
  <pre><code>class Lock
  {
  public:
      Lock(CriticalSection&amp; cs) : cs_(cs)
      {}
  
      Lock(const Lock&amp;) = delete;
      Lock(Lock&amp;&amp;) = delete;
      Lock&amp; operator=(const Lock&amp;) = delete;
      Lock&amp; operator=(Lock&amp;&amp;) = delete;
  
      ~Lock()
      {
          LeaveCriticalSection(&amp;(cs_.cs_));
      }
  
  private:
      CriticalSection&amp; cs_;
  };
  
  
  class CriticalSection
  {
      CRITICAL_SECTION cs_;
  public:
      CriticalSection(const CriticalSection&amp;) = delete;
      CriticalSection&amp; operator=(const CriticalSection&amp;) = delete;
      CriticalSection(CriticalSection&amp;&amp;) = delete;
      CriticalSection&amp; operator=(CriticalSection&amp;&amp;) = delete;
  
      CriticalSection()
      {
          InitializeCriticalSection(&amp;cs_);
      }
  
      ~CriticalSection()
      {
          DeleteCriticalSection(&amp;cs_);
      }
  
      // Usage:  auto lock = criticalSection.MakeLock();
      Lock MakeLock()
      {
          EnterCriticalSection(&amp;cs_);
          return Lock(*this);
      }
  }
  </code></pre>
  
  <p><code>MakeLock</code> returns an instance of a non-movable, non-copyable type. And this seems to work ok. But, Visual Studio intellisense does underline the return in red with a warning that Lock's move constructor can't be referenced as it is a deleted function.</p>
  
  <p>I'm trying to understand why this works and if it is standard conforming C++ or just something peculiar to MSVC. I guess the return works because the need to construct the returned value can be optimized away, so the intellisense warning warns about something that doesn't - in practice - actually happen.</p>
  
  <p>I think I read somewhere that that C++ would standardize on ensuring that return value optimizations would always happen.</p>
  
  <p>So, is this conforming C++ code and will it continue to work in future compilers?</p>
  
  <p>P.S. I realize <code>std::mutex</code> and a <code>std::lock_guard</code> might replace this.</p>