public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kjd at duda dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/20724] function overload resolution fails when any template is declared
Date: Sun, 24 Jul 2005 17:57:00 -0000	[thread overview]
Message-ID: <20050724173341.17742.qmail@sourceware.org> (raw)
In-Reply-To: <20050402005648.20724.kjd@duda.org>


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


  parent reply	other threads:[~2005-07-24 17:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-02  0:56 [Bug c++/20724] New: " 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 [this message]
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
     [not found] <bug-20724-9609@http.gcc.gnu.org/bugzilla/>
2006-12-11 19:21 ` s__nakayama at infoseek dot jp
     [not found] <bug-20724-4@http.gcc.gnu.org/bugzilla/>
2013-05-20 11:00 ` paolo.carlini at oracle dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050724173341.17742.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).