title: RVO/NRVO and public undefined copy constructor
body: <p>I'm fighting the following proposal now, and I want to know legal and for lesser extent moral arguments against it or for it.</p>
  
  <p>What we had:</p>
  
  <pre><code>#include &lt;vector&gt;
  
  class T;
  
  class C
  {
  public:
      C() { }
      ~C( ) { /*something non-trivial: say, calls delete for all elements in v*/ }
      // a lot of member functions that modify C
      // a lot of member functions that don't modify C
  private:
      C(C const &amp;);
      C&amp; operator=(C const&amp;);
  private:
      std::vector&lt; T* &gt; v;
  };
  
  void init(C&amp; c) { } // cannot be moved inside C
  
  // ...
  int main()
  {
      // bad: two-phase initialization exposed to the clients
      C c;
      init(c);
  
      // bad: here follows a lot of code that only wants read-only access to c
      //      but c cannot be declared const
  }
  </code></pre>
  
  <p>What has been proposed:</p>
  
  <pre><code>#include &lt;vector&gt;
  
  class T;
  
  class C
  {
  public:
      C() { }
      ~C( ) { /*calls delete for all elements in v*/ }
  
      // MADE PUBLIC
      C(C const &amp;); // &lt;-- NOT DEFINED
  
      // a lot of member functions that modify C
      // a lot of member functions that don't modify C
  private:
      C&amp; operator=(C const&amp;);
  private:
      vector&lt; T* &gt; v;
  };
  
  C init() // for whatever reason object CANNOT be allocated in free memory
  {
      C c;
      // init c
      return c;
  }
  
  // ...
  int main()
  {
      C const &amp; c = init();
  }
  </code></pre>
  
  <p>This compiles and links (and works) using recent g++ (which is the only target compiler) both 4.1.2 and 4.4.5  -- because of (N)RVO the copy-constructor is never called; destructor is called at the end of main() only.</p>
  
  <p>It is claimed that the technique is perfectly fine, because there is no way copy-constructor could be mis-used (if it ever have been generated it would be linker error), and making it public prevents compiler for complaining about private one.</p>
  
  <p>It looks really-really wrong for me to use such trick, which I feel contradicts the C++ spirit and looks more like hack -- in the bad sense of the word.</p>
  
  <p>My feelings is not sufficient argumentation, so I'm looking for technicalities now.</p>
  
  <p><strong>Please don't post textbook C++ stuff here:</strong></p>
  
  <ul>
  <li>I'm aware of "The Rule of Three" and have read through 12.8/15 and 12.2 of Holy Standard;</li>
  <li>I can use neither <code>vector&lt;shared_ptr&lt;T&gt; &gt;</code> nor <code>ptr_vector&lt;T&gt;</code>;</li>
  <li>I cannot allocate <code>C</code> in free memory and return it from <code>init</code> via <code>C*</code>.</li>
  </ul>
  
  <p>Thank you.</p>