Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Selection of wrong conversion operator

darietti7
Beginner
506 Views
In the following code snippet, the conversion operator for a vector-of-strings is not used. Instead the compiler prefers a template version for a vector-of-T with T=string. The overload should be chosen over the template.

This is not what VS2003 does, and I think Intel compiler does it incorrectly.

---------------------------------------------
#include
#include
#include

struct A
{
// conversion to a vector-of-strings
inline operator std::vector<:STRING> () const
{
std::cout << "operator std::vector<:STRING> ";
return std::vector<:STRING>();
}
// conversion to a vector-of-T
template
inline operator std::vector () const
{
std::cout << "operator std::vector ";
return std::vector();
}
};


int main()
{
const A a;

// uses the apropriate conversion
std::vector vod = a;

// uses the wrong conversion!
std::vector<:STRING> vos = a;

return 0;
}
---------------------------------------------

expected output is (as given by VS2003):
operator std::vector
operator std::vector<:STRING>


wrong result is (given by intel):
operator std::vector
operator std::vector


Is this a bug? compiler is Intel C++ compiler for Windows 9.1.038
Thanks in advance
0 Kudos
6 Replies
JenniferJ
Moderator
506 Views

VC6 gives the same output as IntelC. VC2003 changed.

It is a bug. Could you please file an issue report at Premier Support? So when the fix is available, you'll be notified. I'll also try to update here as well.

Thanks!

0 Kudos
darietti7
Beginner
506 Views
Checked against VS2005 and gcc 3.4.4, got same result (correct) as VS2003
Checked against Intel Compiler 10.0.025, got same result (incorrect) as ICL 9.1.038

Reported to Intel Premier Support: Issue number 454864.

0 Kudos
JenniferJ
Moderator
506 Views

Thanks for submitting the issue at PremierSupport.

There's a work-around for this /Qms0.It tells the compiler to emulate the fewest number of Microsoft compatibility bugs (this is an old bug).

Hope it won't bring anything else up when compiling the whole app.

0 Kudos
support1
Beginner
506 Views
Just so we are clear. This is not a MS bug. The section 14.5.2.2 of the C++ standard says that when you have both, a template and a non-template member function with the same name, the non-template one should be called, unless template arguments explicitly used.
0 Kudos
JenniferJ
Moderator
506 Views

Yes, you're right. I didn't make it clear.

VC2003/VC2005 has the correct behavior, no bug here. It's a bug in icl with /Qvc7.1 and above.

0 Kudos
darietti7
Beginner
506 Views
Hum. I don't feel very comfortable changing the level of compatibility emulation with MS compiler.

I think for now I'd rather change the code to avoid calling the conversion operator for this case, as genericity is not strictly required (but it is still desired!).

I'll just have something like getAsVectorOfStrings() and make the template version not work for strings. I'll retake the conversion approach when a fix is available.

Thanks.

0 Kudos
Reply