title: What are some examples of non-determinism in the C++ compiler?
body: <p>I'm looking for examples of code that triggers non-determinism in GCC or Clang's compilation process.</p>
  
  <p>One prominent example is the usage of the <code>__DATE__</code> macro.</p>
  
  <p>GCC and Clang have a plethora of compiler flags to control the outcome of <strong>non-deterministic actions within the compiler</strong> eg. <code>-frandom-seed</code> and <code>-fno-guess-branch-probability</code></p>
  
  <p>Are there any small examples that are affected by these flags?</p>
  
  <p>To be more precise: </p>
  
  <pre><code>$ c++ main.cpp -o main &amp;&amp; shasum main
  aabbccddee
  
  $ c++ main.cpp -o main &amp;&amp; shasum main
  eeddccbbaa
  </code></pre>
  
  <p>I'm looking for macro-free code examples where multiple runs of the <strong>compiler</strong> lead to different outputs, but can be fixed by e.g. <code>-frandom-seed</code></p>
  
  <p>EDIT:</p>
  
  <p>related: from the <a href="https://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Optimize-Options.html" rel="noreferrer">gcc</a> docs:</p>
  
  <pre><code>-fno-guess-branch-probability:
  Sometimes gcc will opt to use a randomized model to guess branch probabilities, 
  when none are available from either profiling feedback (-fprofile-arcs) 
  or __builtin_expect. 
  This means that different runs of the compiler on the same program
  may produce different object code.
  The default is -fguess-branch-probability at levels -O, -O2, -O3, -Os. 
  </code></pre>