title: What should std::vector::data() return if the vector is empty?
body: <p>According to the draft standard (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf" rel="noreferrer">23.3.6.4 vector data</a>), data() points to the underlying array and <code>[data(), data() + size())</code> must be a valid range:</p>
  
  <pre><code>T* data() noexcept;
  const T* data() const noexcept;
  
      1 Returns: A pointer such that [data(),data() + size()) is a valid range. For a non-empty vector,
  data() == &amp;front().
      2 Complexity: Constant time
  </code></pre>
  
  <p>But what if the vector is empty? When I construct a zero-size vector:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  int main() {
      const int NUM = 0*10;
      std::vector&lt; double &gt; v( NUM, 0.0 );
      std::cerr &lt;&lt; "V : "&lt;&lt; v.data() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>MSVC 2010 returns null, but on Linux (with GCC 4.2.1 and Intel 12.1) I get a non-null address.</p>
  
  <p>Is <code>vector::data()</code> allowed to or should it return null? Could an implementation, for example, do a default-size initial allocation and return a (non-null) pointer to it?</p>
  
  <p><strong>Edit:</strong> Several answers focus on the validity of an empty-range. I fully agree there. </p>
  
  <p>I would really like to see a good reference or explanation for: Is it <em>allowed to</em>, <em>must it</em> return null or <em>may it</em> also return non-null?</p>