title: copy constructor called twice
body: <p>Compiler gcc 4.5.3 (cygwin)</p>
  
  <p>I'm trying to determine under what conditions the copy constructor is called for an argument, and I would like to discover a way to pass an argument that does not require the copy constructor to be called. I constructed the following test code to explore this issue.</p>
  
  <p>In the following code the copy constructor is called twice for fnc1(). Any reason why it should be called more than once?</p>
  
  <p>Is there any way to not have the copy constructor called?</p>
  
  <pre class="lang-c prettyprint-override"><code># include &lt;iostream&gt;
  
  using namespace std;
  
  class able {
  public:
     long x;
     able(): x(1) {}
     able(const able&amp;) {cout &lt;&lt; " const "; }
     ~able() { cout &lt;&lt; " ~able" &lt;&lt; endl; }
  };
  
  able fnc1(able x)         { cout &lt;&lt; "fnc1(able x)"         ; return x; }
  able fnc2(able&amp; x)        { cout &lt;&lt; "fnc2(able&amp; x)"        ; return x; }
  able fnc3(const able&amp;  x) { cout &lt;&lt; "fnc3(const able&amp;  x)" ; return x; }
  able fnc4(able const &amp; x) { cout &lt;&lt; "fnc4(able const &amp; x)" ; return x; }
  able fnc5(able* x)        { cout &lt;&lt; "fnc4(able* x)"        ; return *x; }
  
  int main(int argc, char** argv) {
  
     able* x = new able();
     fnc1(*x);
     fnc2(*x);
     fnc3(*x);
     fnc4(*x);
     fnc5(x);
     cout &lt;&lt; "test fini" &lt;&lt; endl;
     return 0;
  }
  
  output
   const fnc1(able x) const  ~able
    |                 |      |
    |                 |      o first destrucor
    |                 |      
    |                 o second call
    o first call
   ~able
   |
   o second destructor
  fnc2(able&amp; x) const  ~able
  fnc3(const able&amp;  x) const  ~able
  fnc4(able const &amp; x) const  ~able
  fnc4(able* x) const  ~able
  test fini
  </code></pre>