title: C++ Is constructing object twice using placement new undefined behaviour?
body: <p>I have come across some code which has horrified me.
  Essentially it follows this pattern :</p>
  
  <pre><code>class Foo
  {
    public:
      //default constructor
      Foo(): x(0), ptr(nullptr)  
      {
        //do nothing
      }
  
      //more interesting constructor
      Foo( FooInitialiser&amp; init): x(0), ptr(nullptr) 
      {
        x = init.getX();
        ptr = new int;
      }
      ~Foo()
      {
        delete ptr;
      }
  
    private:
      int x;
      int* ptr;
  };
  
  
  void someFunction( FooInitialiser initialiser )
  {
     int numFoos = MAGIC_NUMBER;
     Foo* fooArray = new Foo[numFoos];   //allocate an array of default constructed Foo's
  
     for(int i = 0; i &lt; numFoos; ++i)
     {
         new( fooArray+ i) Foo( initialiser );    //use placement new to initialise
     }
  
      //... do stuff
  
     delete[] fooArray;
  }
  </code></pre>
  
  <p>This code has been in the code base for years and it would seem has never caused a problem. It's obviously a bad idea since someone could change the default constructor to allocate not expecting the second construction. Simply replacing the second constructor with an equivalent initialisation method would seem the sensible thing to do. eg. </p>
  
  <pre><code>void Foo::initialise(FooInitialiser&amp; init)
  {
      x = init.getX();
      ptr = new int;
  }
  </code></pre>
  
  <p>Although still subject to possible resource leaks, at least a defensive programmer might think to check for prior allocations in a normal method. </p>
  
  <p><strong>My question is:</strong></p>
  
  <p>Is constructing twice like this actually undefined behaviour/ outlawed by standard or simply just a bad idea? If undefined behaviour can you quote or point me to right place to look in the standard?</p>