title: Ranged base for loop over temporary reference C++11
body: <p>I'm wondering if the following is valid:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  std::vector&lt;int&gt;&amp; getVec()
  {
      static std::vector&lt;int&gt; vec{1, 2, 3, 4, 5};
      return vec;
  }
  
  int main()
  {
      for (const auto&amp; i : getVec())
      {
          std::cout &lt;&lt; "i = " &lt;&lt; i &lt;&lt; std::endl;
      }
      return 0;
  }
  </code></pre>
  
  <p>Basically I'm unsure about the lifetime of the temporary from <code>getVec()</code>. I've looked at both <a href="https://stackoverflow.com/questions/30448182/is-it-safe-to-use-a-c11-range-based-for-loop-with-an-rvalue-range-init">this post</a> and <a href="https://stackoverflow.com/questions/9657708/c11-the-range-based-for-statement-range-init-lifetime">this one</a>, but am in a bit of a different situation as my function returns a reference to <code>static</code> data. Specifically, I'm wondering if scenario violates the following exception in the stated rule:</p>
  
  <blockquote>
    <ul>
    <li>A temporary bound to a reference parameter in a function call [...]</li>
    </ul>
  </blockquote>
  
  <p>or if this is indeed safe code. I think it is safe, but just wanted to be sure.</p>