This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16915] unnecessary copy construction


------- Additional Comments From boris at kolpackov dot net  2004-08-09 16:15 -------
> Note even if the temporary is gotten rid of (in this case yes it is)

No, it is not. If you replace the following two lines 

private:
  lock_base (lock_base const&);

in the code above with

public:
  lock_base (lock_base const&)
  {
    cerr << "lock_base copy ctor" << endl;
  }

You will see the following output:

operator lock_<mutex>
locking
lock_base copy ctor
unlocking
end of block

> the copy constructor still needs to be accessible

As I said above the copy constructor that should be called (lock_ (lock_
const&)) is accessible.

> read the page which I gave.

I already did. For your convinience I will cite part of the standard that the
page you recommended refers to (if you don't have time to read the whole quote
just read the commend in the example at the end):

8.5.3/5 bullet 2, sub-bullet 1, sub-sub-bullet 2:

  A temporary of type  cv1 T2  [sic] is created, and a constructor is called to
copy the entire rvalue object into the temporary. The reference is bound to the
temporary or to a subobject within the temporary. 

  The constructor that would be used to make the copy shall be callable whether
or not the copy is actually done. 

  [Example: 

   struct A { }; 
   struct B : public A { } b; 
   extern B f();
   const A& rca = f(); // Either bound to the A subobject of the B rvalue,
                       // or the entire B object is copied and the reference
                       // is bound to the A subobject of the copy
  --end example]


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16915


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]