title: "crosses initialization of variable" only when initialization combined with declaration
body: <p>I've read <a href="https://stackoverflow.com/questions/5685471/error-jump-to-case-label">this question</a> about the "jump to case label" error, but I still have some questions. I'm using g++ 4.7 on Ubuntu 12.04.</p>
  
  <p>This code gives an error:</p>
  
  <pre><code>int main() {
    int foo = 1;
    switch(foo) {
    case 1:
      int i = 0;
      i++;
      break;
    case 2:
      i++;
      break;
    }
  }
  </code></pre>
  
  <p>The error is </p>
  
  <pre><code>jump-to-case-label.cpp: In function ‘int main()’:
  jump-to-case-label.cpp:8:8: error: jump to case label [-fpermissive]
  jump-to-case-label.cpp:5:9: error:   crosses initialization of ‘int i’
  </code></pre>
  
  <p>However, this code compiles fine,</p>
  
  <pre><code>int main() {
    int foo = 1;
    switch(foo) {
    case 1:
      int i;
      i = 0;
      i++;
      break;
    case 2:
      i++;
      break;
    }
  }
  </code></pre>
  
  <p>Is the second code any less dangerous than the first? I'm confused as to why g++ allows it.</p>
  
  <p>Secondly, the fix for this problem is to scope the initialized variable. If the initialized variable is a large object, and the switch statement is in a while loop, won't the constructor and destructor be called each time that scope is entered and left, causing a decrease in efficiency? Or will the compiler optimize this away?</p>