another .2003 issue to be verified

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);
}
 
S

Stefan Slapeta

[...]

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

Stefan
 
D

David Lowndes

VC 2003 calls f(char const*) for the following code

VS2005 B1 does the same.

Dave
 
T

Tom Widmer

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
 
S

Stefan Slapeta

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top