This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/31047] New: GCC 4.1.1 has template bug
- From: "satyaakam at yahoo dot co dot in" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 5 Mar 2007 17:11:27 -0000
- Subject: [Bug c++/31047] New: GCC 4.1.1 has template bug
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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