From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Paul J. Lucas" To: gcc-gnats@gcc.gnu.org Subject: c++/3629: nested template constructor doesn't get used as copy constructor Date: Mon, 09 Jul 2001 14:06:00 -0000 Message-id: X-SW-Source: 2001-07/msg00246.html List-Id: 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 template< class T > struct A { A() { } template< class U > A( A const& ) { std::cerr << "Here!\n"; } }; main() { A 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 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: