Re: Type deduction failure due to "invalid conversion" - where is it applicable?
On 5/29/07 10:02 AM, in article
1180429650.255279.139890@m36g2000hse.googlegroups.com,
"int19h@gmail.com" <int19h@gmail.com> wrote:
14.8.2 p.2 of the Standard gives a list of reasons why type deduction
can fail, and among those is one that says, "Attempting to perform an
invalid conversion in either a template argument expression, or an
expression used in the function declaration.". The question is, what
exactly does it apply to? In particular, I have the following example
in my mind:
#include <iostream>
using namespace std;
..
template <class B, class D>
char Foo(Dummy<sizeof((B*)(D*)0)> = 0)
{
return char();
}
struct char_char { char dummy[2]; };
template <class B, class D>
char_char Foo()
{
return char_char();
}
struct A { };
struct B : A { };
struct C : A { };
struct D : B, C { };
int main()
{
Foo<A, D>();
}
In this example, the expression ((B*)(D*)0), which occurs in a
function declaration, and is dependent on the template arguments of
the said function declaration, results in an invalid conversion for
Foo<A, D> specialization, since the cast from D* to A* is ambiguous.
Now, according to the wording of the Standard, should this trigger a
type substitution failure?
No, because the conversion from D* to A* is not invalid. On the
contrary, there are two valid conversions from D* to A*. So the
problem with the sample program is simply that a (valid) conversion
has been specified ambiguously - and not that the conversion itself is
invalid (which would be the case if no D* to A* conversion existed at
all).
Greg
---
[ 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.comeaucomputing.com/csc/faq.html ]