title: How do promotion rules work when the signedness on either side of a binary operator differ?
body: <p>Consider the following programs:</p>
  
  <pre><code>// http://ideone.com/4I0dT
  #include &lt;limits&gt;
  #include &lt;iostream&gt;
  
  int main()
  {
      int max = std::numeric_limits&lt;int&gt;::max();
      unsigned int one = 1;
      unsigned int result = max + one;
      std::cout &lt;&lt; result;
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>// http://ideone.com/UBuFZ
  #include &lt;limits&gt;
  #include &lt;iostream&gt;
  
  int main()
  {
      unsigned int us = 42;
      int neg = -43;
      int result = us + neg;
      std::cout &lt;&lt; result;
  }
  </code></pre>
  
  <p>How does the + operator "know" which is the correct type to return? The general rule is to convert all of the arguments to the widest type, but here there's no clear "winner" between <code>int</code> and <code>unsigned int</code>. In the first case, <code>unsigned int</code> must be being chosen as the result of <code>operator+</code>, because I get a result of <code>2147483648</code>. In the second case, it must be choosing <code>int</code>, because I get a result of <code>-1</code>. Yet I don't see in the general case how this is decidable. Is this undefined behavior I'm seeing or something else?</p>