Consider this program; ================================================ namespace N { int function( char * ) { return 200; }
// uncomment the next line to see a surprising error: //template< typename T > int function(); // The error is: // foo.cpp: In function `int main()': // foo.cpp:15: error: cannot convert `Enum' to `char*' for argument `1' to `int N::function(char*)' }; enum Enum { enum1 }; int function( Enum const & ) { return 100; } int main() { using N::function; function( enum1 ); } ============================================= I would expect this program to compile and for function(enum1) to return 100, regardless of the "template" declaration on line 5. However, if you uncomment the declaration, gcc gets confused and can't find the overload in the main namespace (::function(Enum)). It's like the presence of the template declaration is a little honeypot that gets the overload searcher stuck in the wrong namespace. Oddly, the call to "function(Enum)" and the Enum itself have to be in the *same* namespace to trigger this bug; i.e., if you move the Enum into a namespace separate from main(), the problem goes away. I'd appreciate any feedback here, particularly in the form of "you're crazy" or "this is fixed in gcc version X". Thanks, -Ken -- Summary: function overload resolution fails when any template is declared Product: gcc Version: 3.4.2 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: kjd at duda dot org CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i386-redhat-linux GCC host triplet: i386-redhat-linux GCC target triplet: i386-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20724