When compiling code below, complier says it can't find suitable function:
-
void F( int* ){}
void F( float* ){}
template
void G( T * v)
{
F(v);
}
void F( double* ){}
int main(int, char**)
{
double a = 3.14;
G(&a);
return 0;
}
--
When I rearrange functions in this order:
void F( int* ){}
void F( float* ){}
void F( double* ){}
template void G( T * v) { F(v); }
or in this order:
template void G( T * v) { F(v); }
void F( int* ){}
void F( float* ){}
void F( double* ){}
then all is OK. Only if put G beetween F, then compiler can't see all that
below G.
System information: (gcc -v) and build command:
---
Reading specs from /usr/lib64/gcc/x86_64-slamd64-linux/4.1.2/specs
Target: x86_64-slamd64-linux
Configured with: ../gcc-4.1.2/configure --prefix=/usr --libdir=/usr/lib64
--enable-shared --enable-languages=ada,c,c++,fortran,java,objc
--enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld
--verbose --target=x86_64-slamd64-linux --host=x86_64-slamd64-linux
Thread model: posix
gcc version 4.1.2
g++ -c -pipe -save-temps -Wall -W -g -o test1.o test1.cpp
g++: warning: -pipe ignored because -save-temps specified
test1.cpp: In function 'void G(T*) [with T = double]':
test1.cpp:22: instantiated from here
test1.cpp:12: error: no matching function for call to 'F(double*&)'
test1.cpp:1: note: candidates are: void F(int*)
test1.cpp:5: note: void F(float*)
--
Summary: gcc can't find function, called from template function
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: roman dot desyatov at gmail dot com
GCC build triplet: x86_64-slamd64-linux
GCC host triplet: x86_64-slamd64-linux
GCC target triplet: x86_64-slamd64-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37232