This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/20724] function overload resolution fails when any template is declared


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]