title: Compound assignment in constexpr function: gcc vs. clang
body: <pre><code>template&lt;class A, class B&gt; constexpr int f(A a, B b) {
      a /= b;
      return a;
  }
  
  constexpr int x = f(2, 2);   // a, b: int
  constexpr int y = f(2., 2.); // a, b: double
  constexpr int z = f(2, 2.);  // a: int, b: double //&lt;-- BOOM!
  constexpr int w = f(2., 2);  // a: double, b: int
  
  int main() {}
  </code></pre>
  
  <p>The code doesn't compiled in clang, it produces the following diagnostic:</p>
  
  <pre><code>error: constexpr variable 'z' must be initialized by a constant expression
  </code></pre>
  
  <p>MSVC crashed (according to <a href="https://godbolt.org/z/9trMxI" rel="nofollow noreferrer">godbolt</a>) and gcc works fine. If <code>a /= b</code> is simply replaced by <code>a = a / b</code> then everybody accepts it. Why?</p>
  
  <p>Who is right? Seems it's related to implicit narrowing conversion, but then why <code>a = a / b</code> works?</p>