title: MSVC++ Bad code or compile error with coroutines
body: <p>Good day,<br>
  I'm trying new things in C++ and I found case where Debug and Release configurations in Visual Studio gave me a different results.  </p>
  
  <pre><code>#include &lt;experimental/generator&gt;
  #include &lt;fstream&gt;
  #include &lt;functional&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  
  template &lt;typename T = std::string&gt;
  auto getLineByLine(std::string filename, std::function&lt;T(std::string&amp;)&gt; func = [](std::string&amp; var) { return var; })
  {
      std::ifstream infile(filename);
      std::string line;
  
      while (getline(infile, line))
      {
          yield func(line);
      }
  }
  
  int main()
  {
      std::vector&lt;std::string&gt; myVector;
      for (const auto&amp; line : getLineByLine("fileWithMoreThanOneLine.txt"))
      {
          myVector.push_back(line);
      }
      std::cout &lt;&lt; myVector[0] &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>This code in Debug outputs as expected - one line from file fileWithMoreThanOneLine.txt.<br>
  But in Release it crashes on last line when I'm printing first string in vector.<br>
  When I tried to debug it I found that variable myVector was "optimized away and not available." in Release. I think this is not right optimization.</p>
  
  <p>Also I found that if I change one line to this:<br>
  <code>for (const auto&amp; line : getLineByLine("fileWithMoreThanOneLine.txt", [&amp;myVector](std::string&amp; var) { return var; }))</code><br>
  it compiles correctly. But variable myVector is not needed in lambda function, right?</p>
  
  <p>Is this problem with my code or MSVC compiler? I tried VS 2015 Update 1 (first VS with coroutines) and VS "15" with daily build of VC++.</p>
  
  <p>Thank you,<br>
  Miroslav Hrnčíř</p>
  
  <p>P.S. I'm sorry for my bad English and if it's dumb question.</p>