another .2003 issue to be verified

  • Thread starter Thread starter Stefan Slapeta
  • Start date Start date
S

Stefan Slapeta

VC 2003 calls f(char const*) for the following code, but it should call
the function template as f(char const*) is no perfect match (because of
decay).

Please could someone analyze the behaviour in VC .2005?

Thanks, Stefan


template <typename T>
void f(T const&)
{
// this one should be called!
}

void f(const char *)
{
}

int main()
{
char buf[] = "abc";
f(buf);
}
 
[...]

BTW, seems to no be no open issue for this; I'm going to submit one if
VC 2005 is still wrong.

Stefan
 
Stefan said:
VC 2003 calls f(char const*) for the following code, but it should call
the function template as f(char const*) is no perfect match (because of
decay).

I think it's because of the qualification adjustment actually - decay
alone (a form of Lvalue Transformation) would mean that the two were
ambiguous apart from the second being a non-template, so that would win
(change to void f(char*) to see this effect on a conforming compiler).
See 13.3.3.2/3:

"S1 is a proper subsequence of S2 (comparing the conversion sequences in
the canonical form defined by 13.3.3.1.1, excluding any Lvalue
Transformation; the identity conversion sequence is considered to be a
subsequence of any non-identity conversion sequence)"
Please could someone analyze the behaviour in VC .2005?

Pass, sorry about the unnecessary correction!

Tom
 
Tom said:
I think it's because of the qualification adjustment actually - decay
alone (a form of Lvalue Transformation) would mean that the two were
ambiguous apart from the second being a non-template, so that would win
(change to void f(char*) to see this effect on a conforming compiler).
See 13.3.3.2/3:

"S1 is a proper subsequence of S2 (comparing the conversion sequences in
the canonical form defined by 13.3.3.1.1, excluding any Lvalue
Transformation; the identity conversion sequence is considered to be a
subsequence of any non-identity conversion sequence)"

you are perfectly right - very interesting: if you replace char[] by
char*, the template is called! (that's what confused me when I wrote this).

Stefan
 
Back
Top