title: What does casting to `void` really do?
body: <p>An often used statement like <code>(void)x;</code> allows to suppress warnings about unused variable <code>x</code>. But if I try compiling the following, I get some results I don't quite understand:</p>
  
  <pre><code>int main()
  {
      int x;
      (short)x;
      (void)x;
      (int)x;
  }
  </code></pre>
  
  <p>Compiling this with g++, I get the following warnings:</p>
  
  <pre><code>$ g++ test.cpp -Wall -Wextra -o test
  test.cpp: In function ‘int main()’:
  test.cpp:4:13: warning: statement has no effect [-Wunused-value]
       (short)x;
               ^
  test.cpp:6:11: warning: statement has no effect [-Wunused-value]
       (int)x;
             ^
  </code></pre>
  
  <p>So I conclude that casting to <code>void</code> is very different from casting to any other types, be the target type the same as <code>decltype(x)</code> or something different. My guess at possible explanations is:</p>
  
  <ul>
  <li>It is just a convention that <code>(void)x;</code> but not the other casts will suppress warnings. All the statements equally don't have any effect.</li>
  <li>This difference is somehow related to the fact that <code>void x;</code> isn't a valid statement while <code>short x;</code> is.</li>
  </ul>
  
  <p>Which of these if any is more correct? If none, then how can the difference in compiler warnings be explained?</p>