public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/20724] New: function overload resolution fails when any template is declared
@ 2005-04-02  0:56 kjd at duda dot org
  2005-04-02  0:58 ` [Bug c++/20724] " kjd at duda dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: kjd at duda dot org @ 2005-04-02  0:56 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-07-25 14:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-02  0:56 [Bug c++/20724] New: function overload resolution fails when any template is declared kjd at duda dot org
2005-04-02  0:58 ` [Bug c++/20724] " kjd at duda dot org
2005-04-02  6:16 ` pinskia at gcc dot gnu dot org
2005-04-02 14:27 ` pinskia at gcc dot gnu dot org
2005-07-23 21:29 ` bangerth at dealii dot org
2005-07-24 17:57 ` kjd at duda dot org
2005-07-24 18:21 ` pinskia at gcc dot gnu dot org
2005-07-24 19:28 ` gdr at integrable-solutions dot net
2005-07-25 14:26 ` bangerth at dealii dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).