title: g++'s strict-aliasing warning accuracy
body: <p><a href="https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html" rel="nofollow noreferrer">GCC's documentation</a> says that <code>-Wstrict-aliasing=3</code> is the most accurate level and that lower levels are more likely to give false positives.</p>
  
  <p>I believe the following examples all violate the strict aliasing rule:</p>
  
  <pre><code>float violate1(float a_float)
  {
      float * f_data(&amp;a_float);
      int * i_data((int *)f_data);
      int value(*i_data);
      return value + a_float;
  }
  
  float violate2(float a_float)
  {
      int * i_data((int *)&amp;a_float);
      int value(*i_data);
      return value + a_float;
  }
  
  float violate3(float *f_data)
  {
      int * i_data((int *)f_data);
      int value(*i_data);
      return value + *f_data;
  }
  </code></pre>
  
  <p>Yet g++ only gives warnings for them all when <code>-Wstrict-aliasing=1</code> is used.
  With <code>-Wstrict-aliasing=3</code> no warnings are issued:  <a href="https://godbolt.org/g/aox2S1" rel="nofollow noreferrer">https://godbolt.org/g/aox2S1</a></p>
  
  <p>Are the examples in fact not violations or is it that GCC's warnings are not a reliable indication of violations?</p>