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

* [Bug c++/20724] function overload resolution fails when any template is declared
  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 ` kjd at duda dot org
  2005-04-02  6:16 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: kjd at duda dot org @ 2005-04-02  0:58 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kjd at duda dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20724


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

* [Bug c++/20724] function overload resolution fails when any template is declared
  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
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-02  6:16 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20724


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

* [Bug c++/20724] function overload resolution fails when any template is declared
  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
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-02 14:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-02 14:27 -------
Confirmed (fixed up testcase for -pedantic):
namespace N {
   int foo ( char * ) { return 200; }
   template< typename T > int foo();
}
enum Enum { enum1 };
int foo( Enum const & ) { return 100; }
int main() {
   using N:: foo;
   foo( enum1 );
}


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-04-02 14:27:36
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20724


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

* [Bug c++/20724] function overload resolution fails when any template is declared
  2005-04-02  0:56 [Bug c++/20724] New: function overload resolution fails when any template is declared kjd at duda dot org
                   ` (2 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2005-07-23 21:29 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2005-07-23 21:27 -------
gcc is actually correct. Per the using declaration in main(), you 
introduce N::foo into the scope of foo(), and when foo(enum1) is called 
we find the name foo inside namespace N and then stop to search, so ::foo 
isn't found in any case. 
 
What then happens is this: gcc has one non-template and one template, none 
of which match the function argument, so it says that there is no matching 
function. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20724


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

* [Bug c++/20724] function overload resolution fails when any template is declared
  2005-04-02  0:56 [Bug c++/20724] New: function overload resolution fails when any template is declared kjd at duda dot org
                   ` (3 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: kjd at duda dot org @ 2005-07-24 17:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kjd at duda dot org  2005-07-24 17:33 -------
I will admit I've had difficulty understanding the interaction between scope 
searching and overload resolution, but I cannot believe gcc is handling this 
right.  Consider the example program:

/* 1 */   namespace N {
/* 2 */   int foo ( char * ) { return 200; }
/* 3 */   template< typename T > int foo();
/* 4 */   }
/* 5 */   enum Enum { enum1 };
/* 6 */   int foo( Enum const & ) { return 100; }
/* 7 */   int main() {
/* 8 */      using N:: foo;
/* 9 */      foo( enum1 );
/* 10 */  }

When resolving the call on line 9, either gcc should search the root namespace 
or it should stop after finding "foo" in namespace N.  Whether it searches the 
root namespace should not depend on whether or not one of the overloads in 
namespace N is a template.  Yet with gcc, the program compiles when line 3 is 
commented out, and fails to compile when line 3 is included.  You can add more 
non-matching foo()'s to namespace N, and the program continues to compile, as 
long as none of them is a template.

If Wolfgang's logic in comment 2 were right, then this program would not 
compile:

namespace N {
int foo ( char * ) { return 200; }
int foo() { return 300; }
int foo( int, int ) { return 400; }
}
enum Enum { enum1 };
int foo( Enum const & ) { return 100; }
int main() {
   using N:: foo;
   foo( enum1 );
}

but in fact, it does.

    -Ken


(In reply to comment #2)
> gcc is actually correct. Per the using declaration in main(), you 
> introduce N::foo into the scope of foo(), and when foo(enum1) is called 
> we find the name foo inside namespace N and then stop to search, so ::foo 
> isn't found in any case. 
>  
> What then happens is this: gcc has one non-template and one template, none 
> of which match the function argument, so it says that there is no matching 
> function. 
>  
> W. 



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20724


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

* [Bug c++/20724] function overload resolution fails when any template is declared
  2005-04-02  0:56 [Bug c++/20724] New: function overload resolution fails when any template is declared kjd at duda dot org
                   ` (4 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-24 18:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-24 18:02 -------
Both ICC and Comeau accept this.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |NEW


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20724


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

* [Bug c++/20724] function overload resolution fails when any template is declared
  2005-04-02  0:56 [Bug c++/20724] New: function overload resolution fails when any template is declared kjd at duda dot org
                   ` (5 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: gdr at integrable-solutions dot net @ 2005-07-24 19:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at integrable-solutions dot net  2005-07-24 18:21 -------
Subject: Re:  function overload resolution fails when any template is declared

"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| Both ICC and Comeau accept this.

just a note that since ICC and como are now using the same brand of
front-ends, it may indeed seem strange if they did not agree :-p

-- Gaby


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20724


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

* [Bug c++/20724] function overload resolution fails when any template is declared
  2005-04-02  0:56 [Bug c++/20724] New: function overload resolution fails when any template is declared kjd at duda dot org
                   ` (6 preceding siblings ...)
  2005-07-24 19:28 ` gdr at integrable-solutions dot net
@ 2005-07-25 14:26 ` bangerth at dealii dot org
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2005-07-25 14:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2005-07-25 14:25 -------
As for the initial testcase (Andrew's testcase in comment #1),  
  
- gcc3.3 rejects it with and without the template declaration  
- icc rejects it with and without the template declaration  
- gcc3.4 (and later) rejects it with the template, but accepts it without  
  the template calling ::foo 
 
I believe that the later gcc compilers are in error. They should reject the 
code. 
 
Anyone has other opinions? 
 
W. 

-- 


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).