title: How can I get gcc to warn me about "int i = i;"
body: <p>A simple program:</p>
  
  <pre><code>int main()
  {
      long i = i;
  
      return 0;
  }
  </code></pre>
  
  <p>Compiling as C gives no errors and no warnings.</p>
  
  <pre><code>$ gcc -Wall -Wextra -pedantic 1.c
  </code></pre>
  
  <p>Compiling as C++ gives a warning:</p>
  
  <pre><code>$ c++ -Wall -Wextra -pedantic 1.c
  1.c: In function ‘int main()’:
  1.c:3:7: warning: ‘i’ is used uninitialized in this function [-Wuninitialized]
    long i = i;
  </code></pre>
  
  <p>In both cases variable i seems to be 0, although in c++ it could be uninitialized. I actually made such a typo in one of my functions and it was quite hard to find it. What can I do to avoid this? I'd expect at least a warning. Moreover, Clang doesn't give any warning in either case (c or c++). Is there a specific part of the standard that says anything about this behavior?</p>
  
  <p>Edit: Having tried something similar:</p>
  
  <pre><code>$ cat 1.c
  int main(void)
  {
      int k = k + 0;
      int i = i + 1;
      return 0;
  }
  </code></pre>
  
  <p>The warning (in C) is generated only for "i".</p>
  
  <pre><code>$ gcc -Wall -Wextra 1.c
  1.c: In function ‘main’:
  1.c:4:6: warning: ‘i’ is used uninitialized in this function [-Wuninitialized]
    int i = i + 1;
  </code></pre>