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]

Re: function overloading broken in egcs-980302 ?


David C Binderman wrote:
> 
> Hello there,
> 
> Given the following code on machine i486-pc-linux-gnulibc1, with
> compiler G++ in egcs-980302, I was surprised to find that it compiled ok.
> 
> void
> f( int i)
> {
> };
> 
> void
> f( int & ri)
> {
> };
> 
> I even tried flags -O -Wall -ansi -pedantic, and the code still compiled !
This is not an error.  If you want an error, add these lines to your test-case:

int main(int argc,char** argv)
{
  f(argc); // ERROR!  Ambiguous overload resolution..
  f(1); // OK.  Because 1 is a constant, it can't be passes as a non-const ref
}

With respect to function overloading, C++ takes the stance that a potential
ambiguity is not an error until you attempt to use it.
-- 
Ian Haggard  ||  ian@shellus.com (work)  ||  IanHaggard@juno.com (home)
GNU/Linux -- "Oh, no, Mr Bill!" || #define employer_opinion !my_opinion


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