This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16915] New: unnecessary copy construction
- From: "boris at kolpackov dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Aug 2004 18:34:35 -0000
- Subject: [Bug c++/16915] New: unnecessary copy construction
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
$ cat scope_lock.cxx
#include <iostream>
using std::cerr;
using std::endl;
struct lock_base
{
protected:
lock_base ()
{
}
private:
lock_base (lock_base const&);
};
template <typename T>
struct lock_ : lock_base
{
lock_ (T&)
{
cerr << "locking" << endl;
}
lock_ (lock_ const&)
{
cerr << "copy" << endl;
}
~lock_ ()
{
cerr << "unlocking" << endl;
}
};
typedef lock_base const& lock;
struct mutex
{
operator lock_<mutex> ()
{
cerr << "operator lock_<mutex>" << endl;
return lock_<mutex> (*this);
}
};
template <typename T>
lock_<T> flock (T& t)
{
return lock_<T> (t);
}
int
main ()
{
mutex m;
{
lock l (m);
cerr << "end of block" << endl;
}
}
$ g++-3.4 --version
g++-3.4 (GCC) 3.4.1 (Debian 3.4.1-5)
$ g++-3.4 scope_lock.cxx
scope_lock.cxx: In function `int main()':
scope_lock.cxx:20: error: `lock_base::lock_base(const lock_base&)' is private
scope_lock.cxx:67: error: within this context
Strangely, gcc tries to perform derived-to-base conversion and copy construction
when just derived-to-base conversion is already enough. The same code compiles
fine with icc 8.
--
Summary: unnecessary copy construction
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: boris at kolpackov dot net
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16915