https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71590
Bug ID: 71590 Summary: G++ template function initialize with wrong type Product: gcc Version: 4.4.4 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: markowitz73 at gmail dot com Target Milestone: --- The source code is as below: //source start #include <string> template <class T> std::string func(T a, int b) { std::string x; int y; if (b == 1) { x = a; } else if (b == 2) { y = a; } return x; } int main() { std::string c = func<int>(1, 1); return 0; } //source ends this file got compiled successfully. Since there is no overload operator=(int) version for std::string, so I think that I may came across with a bug. Anything maybe useful: I tried to output the std::string object which was assigned by an integer, it shows that the string was initialized by a char(the first argument 1 was treated as a char), and the output is ASCII represented by that integer. Compile Option: g++ -o source.cpp main Compiler Info: g++ -v shows:Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)