[Bug c++/31047] New: GCC 4.1.1 has template bug
satyaakam at yahoo dot co dot in
gcc-bugzilla@gcc.gnu.org
Mon Mar 5 17:11:00 GMT 2007
We've uncovered a GCC 4.1.1 template bug when we compile using GCC4.1.1,This
simple testcase shows the issue.
#include <iostream>
template< typename T > void foo( T var) { std::cout << "T" << std::endl; }
template < typename T> void doit( T var ) { foo(var); }
void foo(const int& var) { std::cout << "INT" << std::endl; }
int main() {
doit(3); // prints T
return 0;
}
/////////////// temp.cpp ////////////////////////////////
Run the example with gcc 3.2.3
rm -f a.out
$/v3.2.3/bin/g++ -Wall temp.cpp
LD_LIBRARY_PATH=/v3.2.3/lib:$LD_LIBRARY_PATH; a.out
[~/test]$ gcc3
INT
Now run with GCC 4.1.1
[~/test]$ more gcc4
rm -f a.out
$/v4.1.1/bin/g++ -Wall temp.cpp
LD_LIBRARY_PATH=/v4.1.1/lib:$LD_LIBRARY_PATH; a.out
[georgef@sdvlx32 ~/test]$ gcc4
T
We can fix this particular example by moving
void foo(const int& var) { std::cout << "INT" << std::endl; }
to the top of the function. However, this won't work in more complex cases.
--
Summary: GCC 4.1.1 has template bug
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: satyaakam at yahoo dot co dot in
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31047
More information about the Gcc-bugs
mailing list