title: Is a copy-on-return operation executed prior or after lock_guard destructor?
body: <p>Is the <code>get_a()</code> function safe for race-conditions or do I need to explicitly copy <code>str_</code> as in <code>get_b()</code> in order to have a thread-safe function?</p>
  
  <pre><code>class Class {
  public:
    auto get_a() -&gt; std::string {
      auto&amp;&amp; guard = std::lock_guard{mutex_};
      return str_;
    }
    auto get_b() -&gt; std::string {
      auto&amp;&amp; guard = std::lock_guard{mutex_};
      auto str = str_;
      return str;
    }
  private:
    std::mutex mutex_{};
    std::string str_{};
  };
  </code></pre>
  
  <p><em>Note: I'm aware that there are similar questions here on Stack Overflow, but I could not find one which explicitly answers this question.</em></p>