Topic: Ambiguous call or compiler bug?


Author: richards_corden@hotmail.com (Richard Corden)
Date: Thu, 14 Aug 2003 18:11:58 +0000 (UTC)
Raw View
<CODE>
  template <typename T>
  int bar (T t1, T t2);

  template <typename T>
  int bar (T t, int); // more specialized?

  void func ()
  {
    bar (10, 20);
  }
</CODE>

It seems to me that the second overload of bar is 'more specialized'
than the first, yet most of my compilers say its ambiguous?

Any thoughts?

Kind Regards,

Richard


--
Richard Corden
To reply remove 's' from address

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: wolof@freemail.hu ("White Wolf")
Date: Thu, 14 Aug 2003 18:56:39 +0000 (UTC)
Raw View
Richard Corden wrote:
> <CODE>
>   template <typename T>
>   int bar (T t1, T t2);
>
>   template <typename T>
>   int bar (T t, int); // more specialized?
>
>   void func ()
>   {
>     bar (10, 20);
>   }
> </CODE>
>
> It seems to me that the second overload of bar is 'more specialized'
> than the first, yet most of my compilers say its ambiguous?
>
> Any thoughts?

Just one: it is overloaded, not specialized.  Function templates (AFAIU)
cannot be specialized.

WW aka Attila


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: jdennett@acm.org (James Dennett)
Date: Thu, 14 Aug 2003 22:32:16 +0000 (UTC)
Raw View
Richard Corden wrote:
> <CODE>
>   template <typename T>
>   int bar (T t1, T t2);
>
>   template <typename T>
>   int bar (T t, int); // more specialized?
>
>   void func ()
>   {
>     bar (10, 20);
>   }
> </CODE>
>
> It seems to me that the second overload of bar is 'more specialized'
> than the first, yet most of my compilers say its ambiguous?

It appears to me that neither is more specialized than the
other: there are calls to each that can't be made to the
other.

template <typename T> int bar(int, int);
is more specialized that either, of course.

-- James.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: jpotter@falcon.lhup.edu (John Potter)
Date: Fri, 15 Aug 2003 01:29:15 +0000 (UTC)
Raw View
On Thu, 14 Aug 2003 18:56:39 +0000 (UTC), wolof@freemail.hu ("White
Wolf") wrote:

> Richard Corden wrote:
> > <CODE>
> >   template <typename T>
> >   int bar (T t1, T t2);

> >   template <typename T>
> >   int bar (T t, int); // more specialized?

> >   void func ()
> >   {
> >     bar (10, 20);
> >   }
> > </CODE>

> > It seems to me that the second overload of bar is 'more specialized'
> > than the first, yet most of my compilers say its ambiguous?

> > Any thoughts?

> Just one: it is overloaded, not specialized.

Correct.  The question is which if either overload is more
specialized.  See 14.5.5.2.

> Function templates (AFAIU) cannot be specialized.

They can, but they may not be partially specialized.  Also, each
instantiation is a specialization.  Hard to follow the words.

Getting back to the original question, I will attempt an answer to
see if I understand 14.5.5.2.

We create a type, say Q.  Using that for T in the first version gives
a call of bar(Q, Q).  Argument deduction in the second version fails
with that call giving the first is not more specialized than the second.
Using that for T in the second gives bar(Q, int).  Argument deduction in
the first version fails with that call giving the second is not more
specialized than the first.  Since neither overload is more specialized
than the other, the call is ambiguous.

John

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: chris@bubblescope.net (chris)
Date: Sun, 17 Aug 2003 18:58:58 +0000 (UTC)
Raw View
Richard Corden wrote:
> <CODE>
>   template <typename T>
>   int bar (T t1, T t2);
>
>   template <typename T>
>   int bar (T t, int); // more specialized?

The second isn't a specialized version of the first one, as in the first
one you require both of the types to be the same

>
>   void func ()
>   {
>     bar (10, 20);
>   }
> </CODE>
>
> It seems to me that the second overload of bar is 'more specialized'
> than the first, yet most of my compilers say its ambiguous?
>
> Any thoughts?
>
> Kind Regards,
>
> Richard
>
>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]