title: C++ Ternary Operator Calls Copy Constructor Instead of Move Constructor
body: <p>I'm using VS Code to compile and debug with g++ in Linux.</p>
  <p>Needed includes and usings:</p>
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  </code></pre>
  <p>Here is my class which is moveable:</p>
  <pre><code>class A {
  public:
      A(const string&amp; strA) : strA(strA) {}
  
      A(const A&amp; a) : A(a.strA) {
      }
  
      A(A&amp;&amp; a) : A(a.strA) {
          a.strA = &quot;&quot;;
      }
  
      string strA;
  };
  </code></pre>
  <p>Example function that returns an instance of A:</p>
  <pre><code>A RetA() {
      A a(&quot;a&quot;);
      A b(&quot;bha&quot;);
  
      string ex;
      cin &gt;&gt; ex;
      a.strA += ex;
  
      return ex == &quot;123&quot; ? a : b;
  }
  </code></pre>
  <p>And here is the simple main:</p>
  <pre><code>int main() {
      A a(RetA());
  
      return 0;
  }
  </code></pre>
  <p>And returning value in the RetA function is <strong>copied</strong>, <strong>not moved</strong>. Why?</p>
  <p><strong>On the other hand</strong>, if we use &quot;explicitly if&quot; instead of ternary operator in the RetA function:</p>
  <pre><code>A RetA() {
      A a(&quot;a&quot;);
      A b(&quot;bha&quot;);
  
      string ex;
      cin &gt;&gt; ex;
      a.strA += ex;
  
      if (ex == &quot;123&quot;)
          return a;
  
      return b;
  }
  </code></pre>
  <p>Then it is <strong>moved</strong>, <strong>not copied</strong>. This is already expected behaviour. But it is strange that move operation doesn't work with ternary operator. Should it be like that or is it a bug or something for VS Code etc?</p>