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]

c++/3629: nested template constructor doesn't get used as copy constructor


	Note: There was a bad value `wrong' for the field `>Class:'.
	It was set to the default value of `sw-bug'.


>Number:         3629
>Category:       c++
>Synopsis:       nested template constructor doesn't get used as copy constructor
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 09 14:06:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Paul J. Lucas
>Release:        3.0
>Organization:
>Environment:
System: Linux powerbook 2.2.17 #2 Wed Nov 22 16:34:45 PST 2000 ppc unknown
Architecture: ppc
host: powerpc-unknown-linux-gnu
build: powerpc-unknown-linux-gnu
target: powerpc-unknown-linux-gnu
configured with: ./configure --prefix=/usr/local/packages/gcc-3.0 --enable-languages=c++
>Description:
	A used-defined template copy constructor inside a template class
	doesn't get used to generate a copy constructor when the types equal.
>How-To-Repeat:
#include <iostream>

template< class T > struct A {
	A() { }
	template< class U > A( A<U> const& )	{ std::cerr << "Here!\n"; }
};

main() {
	A<int> a;
	/*
	** The line below should cause "Here!" to be printed because, when the
	** type T = type U, it matches the signature of a copy constructor and
	** the one defined above should be called.  However, the compiler
	** still generates a default copy constructor and doesn't use the above
	** one.
	*/
	A<int> b( a );
}
>Fix:
	A non-template copy constructor can be written explicitly, e.g.:

		A( A const& );

	but the user shouldn't have to.

>Release-Note:
>Audit-Trail:
>Unformatted:


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