Package: g++-4.1
Version: 4.1.1-11
Severity: normal
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&)'
$
-- System Information:
Debian Release: testing/unstable
APT prefers oldstable
APT policy: (500, 'oldstable'), (500, 'testing'), (500, 'stable')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/dash
Kernel: Linux 2.6.17.9
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Versions of packages g++-4.1 depends on:
ii gcc-4.1 4.1.1-11 The GNU C compiler
ii gcc-4.1-base 4.1.1-11 The GNU Compiler Collection (base
ii libc6 2.3.6.ds1-4 GNU C Library: Shared libraries
ii libstdc++6-4.1-dev 4.1.1-11 The GNU Standard C++ Library v3 (d
g++-4.1 recommends no packages.
-- no debconf information
--
Vincent Zweije <zweije@xs4all.nl> | "If you're flamed in a group you
<http://www.xs4all.nl/~zweije/> | don't read, does anybody get burnt?"
[Xhost should be taken out and shot] | -- Paul Tomblin on a.s.r.
Attachment:
signature.asc
Description: Digital signature