title: Can an unsigned integer addition invoke undefined behavior?
body: <p><strong>Edit:</strong> Changed the value for <code>USHRT_MAX</code> as it was not conformant as shown by comments.</p>
  
  <hr>
  
  <p>Imagine you have a fancy compiler where its integer type limits, as defined in <em>limits.h</em> are:</p>
  
  <pre><code>#define INT_MAX   2147483647   /* Typical 32-bit system value */
  #define USHRT_MAX 2147483647   /* ***Edited***, original question had 2000000000 */
  </code></pre>
  
  <p>And in my application I have the following code:</p>
  
  <pre><code>unsigned short a = 1500000000;
  unsigned short b = 1500000000;
  unsigned short c;
  c = a + b;
  </code></pre>
  
  <p>As far as I know, what will happen in the last instruction will be:</p>
  
  <ol>
  <li>Integral promotion on <code>a</code>. As <code>int</code> can take all values of <code>unsigned short</code>, <code>a</code> gets promoted to <code>int</code>.</li>
  <li>For the same reasons, <code>b</code> gets promoted to <code>int</code>.</li>
  <li>Addition happens on <code>int</code> types.</li>
  <li>The result is not representable in <code>int</code>. Undefined Behavior due to paragraph 6.5/5.</li>
  </ol>
  
  <p>Is my reasoning correct? Does this really invoke undefined behavior, or where did I go wrong? Note that my code only works with unsigned types, and a result applying the modulus for unsigned integers could be expected due to legal overflow on unsigned types.</p>
  
  <p>If the answer to the previous question is "<em>yes, undefined behavior</em>", this happened for a legal conformant compiler. So, can you say that the application code I posted is incorrect? Do all non-explicitly-casted small unsigned integer additions potentially invoke undefined behavior?</p>