Re: How to subscript a CString? (CSimpleStringT::operator[])
Mr. Harrison, thank you for your analysis and recommendation, but there are
two reasons why I am not likely to submit this to the Connect site. If you
are sure that this is a compiler bug and if you think there's a chance of
getting it fixed, you obviously have a repro case and there would be nothing
wrong if you submit it to the Connect site.
Until I have time to read and interpret sections of the standard on overload
resolution and its relationship to standard integral promotions, I will not
feel confident in making an assertion myself that this is a compiler bug
(though I can still call it suspicious).
Also Microsoft has told me, in the Connect site for Visual Studio bugs, that
Microsoft cannot deal with an error message that Microsoft displays in
Japanese, even when I provided Microsoft with a rough translation of
Microsoft's error message into English. Microsoft has given some of my
Connect submissions on Visual Studio better treatment than my submissions on
Vista, but I still don't feel encouraged to waste too much time on it.
"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:dvm1v2tuftj40cqeho9uoqoip661v5h9k8@4ax.com...
I believe this fragment models your example:
struct X
{
int operator[](int);
operator int*();
};
void f(X& x)
{
int y = x[short(1)];
}
VC8 emits the error:
X>cl -c a.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for
80x86
Copyright (C) Microsoft Corporation. All rights reserved.
a.cpp
a.cpp(9) : error C2666: 'X::operator []' : 2 overloads have similar
conversions
a.cpp(3): could be 'int X::operator [](int)'
or 'built-in C++ operator[(int *, short)'
while trying to match the argument list '(X, short)'
This is a bug. Both candidate functions require promotion of short to int,
but the operator[] is an exact match for the implicit object parameter,
while the conversion operator requires conversion of it to int*, which is
worse. (Reading the error message literally, it's like the compiler
ignores
the user-defined conversion that occurs when it applies operator*, and to
make matters worse, ignores the fact that short is promoted to int, so
there cannot be any such "signature" for the built-in operator.) Because
operator[] provides a better match on one of the arguments and isn't worse
on the other, it should be selected. You might want to report this here:
http://connect.microsoft.com/feedback/default.aspx?SiteID=210
Post back with the URL, and I'll verify it.
--
Doug Harrison
Visual C++ MVP