title: How is this object's destructor being called two times?
body: <p>Can someone please explain how test1 is getting destroyed 2 times? Compiled with Visual Studio C++17</p>
  <pre class="lang-cpp prettyprint-override"><code>class test {
  public:
      test(int val):val_(val) {
          cout &lt;&lt; &quot;test&quot; &lt;&lt; val_ &lt;&lt; &quot;constructor called\n&quot;;
      }
      ~test() {
          cout &lt;&lt; &quot;test&quot; &lt;&lt; val_ &lt;&lt; &quot; destructor called\n&quot;;
      }
      int val_;
  };
  
  int main() {
      auto t2 = test(2);
      {
          auto t1 = test(1);
           swap(t1, t2);
      }
      return 0;
  }
  </code></pre>
  <p>Output:</p>
  <pre class="lang-none prettyprint-override"><code>test2constructor called
  
  test1constructor called
  
  test1 destructor called
  
  test2 destructor called
  
  test1 destructor called
  </code></pre>