When compiling the following code, g++ goes into an infinite loop. --- start of loop.cpp ------------------ class A {}; template <typename T> class X : public A { public: X(T&); }; class B { public: bool foo(A*); template <typename T> bool foo(T& t) { return foo(new X<T>(t)); } }; int main() { B x, y; x.foo(y); } --- end of loop.cpp ---------------- $ g++ -c loop.cpp [never finishes] Compiler version is: $ g++ -v Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux Thread model: posix gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) Also verified the same behavior with g++ 3.3.1, compiled with the same configure options.
This is fixed on the mainline (20030918). Actually it is not an infinite loop but taking a very long time because of -ftemplate-depth is large in 3.2 and above (until the mainline). In 3.0.4 where the -ftemplate-depth is small this is rejected almost right away which is wrong. The real problem is that GCC is not selecting bool foo(A*); but always selecting the template version of foo which is wrong. Also this is a regression from 2.95.3 which GCC accepted this code. According to Phil's regression hunter this is fixed: between 2003-09-03-trunk (#390) and 2003 -09-04-trunk (#391). Also note it is busted between 2.95 was released and 2000-12-31.
Subject: Bug 12337 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: mmitchel@gcc.gnu.org 2003-10-07 05:57:07 Modified files: gcc/cp : ChangeLog call.c decl.c init.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/ext: attrib8.C gcc/testsuite/g++.dg/init: new9.C Log message: PR c++/10174 * call.c (initialize_reference): Tweak error message. PR c++/12337 * init.c (build_new_1): Make sure that the expression returned is not an lvalue. PR c++/12344, c++/12236, c++/8656 * decl.c (start_function): Do not ignore attributes embedded in a function declarator. PR c++/12337 * g++.dg/init/new9.C: New test. PR c++/12334, c++/12236, c++/8656 * g++.dg/ext/attrib8.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.212&r2=1.3076.2.213 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.341.2.33&r2=1.341.2.34 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.965.2.62&r2=1.965.2.63 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.299.2.9&r2=1.299.2.10 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.299&r2=1.2261.2.300 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/attrib8.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/new9.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
Subject: Bug 12337 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2003-10-07 07:07:08 Modified files: gcc/cp : ChangeLog call.c cxx-pretty-print.c cxx-pretty-print.h decl.c init.c gcc/testsuite : ChangeLog gcc/testsuite/g++.dg/other: error4.C gcc/testsuite/g++.dg/template: ptrmem4.C Added files: gcc/testsuite/g++.dg/ext: attrib8.C gcc/testsuite/g++.dg/init: new9.C Log message: PR c++/10147 * call.c (initialize_reference): Tweak error message. PR c++/12337 * init.c (build_new_1): Make sure that the expression returned is not an lvalue. PR c++/12344, c++/12236, c++/8656 * decl.c (start_function): Do not ignore attributes embedded in a function declarator. PR c++/12337 * g++.dg/init/new9.C: New test. PR c++/12334, c++/12236, c++/8656 * g++.dg/ext/attrib8.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3717&r2=1.3718 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.437&r2=1.438 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cxx-pretty-print.c.diff?cvsroot=gcc&r1=1.7&r2=1.8 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cxx-pretty-print.h.diff?cvsroot=gcc&r1=1.4&r2=1.5 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1139&r2=1.1140 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.344&r2=1.345 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3099&r2=1.3100 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/attrib8.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/new9.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/other/error4.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem4.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
Fixed in GCC 3.3.2 and GCC 3.4.