[forwarded from http://bugs.debian.org/385992]
Matthias bug submitter writes: It appears that g++ no longer finds a dependent name when it is the template function itself. $cat -n test.cpp 1 template <class C> void f(C *p) 2 { f(*p); } 3 4 void f(int i) 5 { i++; } 6 7 int main(int argc, char**) 8 { f(&argc); } $g++-4.0 -o test test.cpp $g++-4.1 -o test test.cpp test.cpp: In function 'void f(C*) [with C = int]': test.cpp:8: instantiated from here test.cpp:2: error: no matching function for call to 'f(int&)' $ To my understanding from the C++ standard, g++-4.0 behaves correctly. My reasoning: In f(*p), f is a dependent name according to clause 14.6.2, para 1. The point of instantiation is f(&argc). In f(*p), f is an unqualified-id but not a template-id, so 14.6.4.2 applies: only functions with external linkage will be found. However, f(int) has external linkage. Name lookup (3.4, 3.4.2) does not distinguish between the different contexts for the case of an instantiated instantiation. So, the lookup of f in f(*p) should consider f<C>(C*) and f(int) together, and select f(int) from them. When f(int) and its call in the template are renamed to something else, the lookup succeeds. I do not know of a reason for having template f hide the existence of function f. g++ -v output for upstream: $g++-4.1 -v -o test test.cpp Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --with-tune=i686 --enable-checking=release i486-linux-gnu Thread model: posix gcc version 4.1.2 20060814 (prerelease) (Debian 4.1.1-11) /usr/lib/gcc/i486-linux-gnu/4.1.2/cc1plus -quiet -v -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=i686 -auxbase test -version -o /home/vzweije/tmp/ccgs0DVY.s ignoring nonexistent directory "/usr/local/include/i486-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../i486-linux-gnu/include" ignoring nonexistent directory "/usr/include/i486-linux-gnu" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2 /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward /usr/local/include /usr/lib/gcc/i486-linux-gnu/4.1.2/include /usr/include End of search list. GNU C++ version 4.1.2 20060814 (prerelease) (Debian 4.1.1-11) (i486-linux-gnu) compiled by GNU C version 4.1.2 20060814 (prerelease) (Debian 4.1.1-11). GGC heuristics: --param ggc-min-expand=46 --param ggc-min-heapsize=31550 Compiler executable checksum: af253f4d4c50ecb6c5ed3e2466348eaf test.cpp: In function 'void f(C*) [with C = int]': test.cpp:8: instantiated from here test.cpp:2: error: no matching function for call to 'f(int&)' $ -- Summary: g++ fails to find dependent name in template from instantiation context Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: debian-gcc at lists dot debian dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29229