title: Is it now wrong to "return" from a "switch" statement in C++11?
body: <p>Using VS2012, I noticed that a <code>switch</code> that's been working for several years now seems to be broken in Release builds but works correctly (or at least as it used to) in Debug builds. I can't see anything at all wrong with the code so would appreciate some feedback on the correctness of using <code>return</code> statements from within a <code>switch</code> block.</p>
  
  <p>The following code compiles ok but gives the wrong output in a Release build on Win7 32-bit...</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;tchar.h&gt;
  
  class CSomeClass
  {
  public:
      float GetFloat(int nInt)
      {
          printf("GetFloat() - entered\n");
          switch (nInt)
          {
          case 1 :
              printf("GetFloat() - case 1 entered\n");
              return 0.5F;
          case 0 :
              printf("GetFloat() - case 0 entered\n");
              return 1.0F;
          case 2 :
              printf("GetFloat() - case 2 entered\n");
              return 2.0F;
          case 3 :
              printf("GetFloat() - case 3 entered\n");
              return 3.0F;
          case 4 :
              printf("GetFloat() - case 4 entered\n");
              return 4.0F;
          }
          printf("GetFloat() - exit\n");
          return 1.0F;
      }
  };
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      CSomeClass pClass;
      float fValue = pClass.GetFloat(3);
      printf("fValue = %f\n", fValue);
  
      return 0;
  }
  </code></pre>
  
  <p>If you can repeat the problem, and have a MS Connect login, maybe you can vote it up here too?</p>
  
  <p><strong>Actual results</strong></p>
  
  <p>Release build gives the following incorrect result:</p>
  
  <pre><code>GetFloat() - entered
  GetFloat() - case 3 entered
  fValue = 0.000000
  </code></pre>
  
  <p><strong>Expected results</strong></p>
  
  <p>Debug build gives the following correct result:</p>
  
  <pre><code>GetFloat() - entered
  GetFloat() - case 3 entered
  fValue = 3.000000
  </code></pre>
  
  <p><a href="https://connect.microsoft.com/VisualStudio/feedback/details/779043/c-switch-statement-broken-in-release-build#details" rel="noreferrer" title="MS Connect bug report">MS Connect bug report</a></p>