title: Why do gcc and clang each produce different output for this program? (conversion operator vs constructor)
body: <p>program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  struct bar_t {
      int value;
      template&lt;typename T&gt;
      bar_t (const T&amp; t) : value { t } {}
  
      // edit: You can uncomment these if your compiler supports
      //       guaranteed copy elision (c++17). Either way, it 
      //       doesn't affect the output.
  
      // bar_t () = delete;
      // bar_t (bar_t&amp;&amp;) = delete;
      // bar_t (const bar_t&amp;) = delete;
      // bar_t&amp; operator = (bar_t&amp;&amp;) = delete;
      // bar_t&amp; operator = (const bar_t&amp;) = delete;
  };
  
  struct foo_t {
      operator int   () const { return 1; }
      operator bar_t () const { return 2; }
  };
  
  int main ()
  {
      foo_t foo {};
      bar_t a { foo };
      bar_t b = static_cast&lt;bar_t&gt;(foo);
  
      printf("%d,%d\n", a.value, b.value);
  }
  </code></pre>
  
  <p>output for <strong>gcc</strong> 7/8:</p>
  
  <pre><code>2,2
  </code></pre>
  
  <p>output for <strong>clang</strong> 4/5 (also for gcc 6.3)</p>
  
  <pre><code>1,1
  </code></pre>
  
  <p>It seems that the following is happening when creating the instances of <code>bar_t</code>:</p>
  
  <p>For <strong>gcc</strong>, it <code>calls foo_t::operator bar_t</code> then <code>constructs bar_t with T = int</code>.</p>
  
  <p>For <strong>clang</strong>, it <code>constructs bar_t with T = foo_t</code> then <code>calls foo_t::operator int</code></p>
  
  <p>Which compiler is correct here? (or maybe they are both correct if this is some form of undefined behaviour)</p>