title: would the pointer returned by new(size, value) Type[0] be legal and could it be used to build an array?
body: <p>The standard says, in <code>5.3.4[expr.new]/7</code></p>
  
  <blockquote>
    <p>When the value of the expression in a direct-new-declarator is zero, the allocation function is called to allocate an array with no elements.</p>
  </blockquote>
  
  <p>and in <code>3.7.3.1[basic.stc.dynamic.allocation]/2</code></p>
  
  <blockquote>
    <p>The effect of dereferencing a pointer returned as a request for zero size is undefined.</p>
  </blockquote>
  
  <p>But if the allocation function is user-defined and it knows it returned a valid pointer, would it still be undefined behavior to dereference it? Can the standard mandate undefined behavior of user code?</p>
  
  <p>The reason I ask is yet another meaningless attempt to initialize a dynamic array of objects of non-default-constructible type. What problems does it have, besides the obvious lack of <code>delete[]</code> and that it can only be called with <code>[0]</code>? Did I even use <code>aligned_storage</code> correctly?</p>
  
  <pre><code>#include &lt;type_traits&gt;
  #include &lt;stdexcept&gt;
  #include &lt;memory&gt;
  #include &lt;iostream&gt;
  
  struct T {
     int val;
     T() = delete;
     T(int i) : val(i) {}
     void* operator new[](std::size_t, std::size_t cnt, const T&amp; t)
     {
         typedef std::aligned_storage&lt;sizeof(t),
                      std::alignment_of&lt;T&gt;::value&gt;::type buf;
         T* ptr = reinterpret_cast&lt;T*&gt;(new buf[cnt]);
         std::uninitialized_fill_n(ptr, cnt, t);
         return ptr;
      }
  };
  
  int main()
  {
      T* a = new(100, T(7)) T[0]; // using zero is legal per 5.3.4/7
  
      std::cout &lt;&lt; "a[0] = " &lt;&lt; a[0].val &lt;&lt; '\n' // but is this legal?
                &lt;&lt; "a[1] = " &lt;&lt; a[1].val &lt;&lt; '\n'
                &lt;&lt; "a[98] = " &lt;&lt; a[98].val &lt;&lt; '\n'
                &lt;&lt; "a[99] = " &lt;&lt; a[99].val &lt;&lt; '\n';
      delete[] a; // free the 100 aligned_storages
  }
  </code></pre>
  
  <p>test run: <a href="http://ideone.com/iBW0z" rel="nofollow">http://ideone.com/iBW0z</a></p>
  
  <p>also compiles and runs as expected with  with MSVC++ 2010 EE</p>