Topic: Defect Report: Partial ordering and non-deduced arguments
Author: rani_sharoni@hotmail.com (Rani Sharoni)
Date: Tue, 20 Jan 2004 19:56:29 +0000 (UTC) Raw View
[Note: Forwarded to C++ Commitee -sdc ]
It's not clear how overloading and partial ordering handle non-deduced pairs
of corresponding arguments. For example:
template<typename T>
struct A { typedef char* type; };
template<typename T> char* f1(T, typename A<T>::type); // #1
template<typename T> long* f1(T*, typename A<T>::type*); // #2
long* p1 = f1(p1, 0); // #3
I thought that #3 is ambiguous but different compilers disagree on that.
Comeau C/C++ 4.3.3 (EDG 3.0.3) accepted the code, GCC 3.2 and BCC 5.5
selected #1 while VC7.1+ yields ambiguity.
I intuitively thought that the second pair should prevent overloading from
triggering partial ordering since both arguments are non-deduced and has
different types - (char*, char**). Just like in the following:
template<typename T> char* f2(T, char*); // #3
template<typename T> long* f2(T*, char**); // #4
long* p2 = f2(p2, 0); // #5
In this case all the compilers I checked found #5 to be ambiguous.
The standard and DR #214 is not clear about how partial ordering handle such
cases.
I think that overloading should not trigger partial ordering (in step
13.3.3/1/5) if some candidates have non-deduced pairs with different
(specialized) types. In this stage the arguments are already adjusted so no
need to mention it (i.e. array to pointer). In case that one of the
arguments is non-deuced then partial ordering should only consider the type
from the specialization:
template<typename T> struct B { typedef T type; };
template<typename T> char* f3(T, T); // #7
template<typename T> long* f3(T, typename B<T>::type); // #8
char* p3 = f3(p3, p3); // #9
According to my reasoning #9 should yield ambiguity since second pair is (T,
long*). The second type (i.e. long*) was taken from the specialization
candidate of #8.
EDG and GCC accepted the code. VC and BCC found an ambiguity.
Thanks,
Rani
[ 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 ]