title: GCC Compiler gives warning for a static variable defined and used
body: <p>Consider the sample code below :</p>
  
  <p><strong>File1.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  static int x = 6;                          // line 3
  
  int main()
  {
     int x = 10;                             // line 7
     {
        extern int x;                        // line 9
        x = x + 5;
        std::cout &lt;&lt; "x = " &lt;&lt; x &lt;&lt; "\n";
     }
  }
  </code></pre>
  
  <p>The external declaration in line 9 causes <code>x</code> in the following lines to refer to the static <code>x</code> (defined in line 3) instead of the automatic <code>x</code> (defined in line 7). But I get the following compiler warning:</p>
  
  <blockquote>
    <p>File1.cpp:3: warning: 'x' defined but not used</p>
  </blockquote>
  
  <p>Even with this warning, I get the expected output which is <code>x = 11</code>, which is 5 added to the value of the static variable <code>x</code>.</p>
  
  <p>Why is the compiler giving the above warning? I am using GCC version <code>g++ (GCC) 3.4.6</code>.</p>