Search

Ambiguous use of the overloaded function std::string to_string(int val); by Сыроежка

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 742642
Opened: 5/18/2012 4:21:56 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
The function std::string to_string(int val); does not declared for the fundamental type int. So the compiler issues errors that the use of the function is ambiguous. Header <string> contains the following declarations

inline string to_string(_Longlong _Val);
inline string to_string(_ULonglong _Val);
inline string to_string(long double _Val);

where _Longlong and _ULonglong are defined as

#define _LONGLONG    __int64
#define _ULONGLONG    unsigned __int64

So then there is a call

int x = 42;

std::string s = to_string( x );

the compiler issues errors.

Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010 SP1

Steps to reproduce

#include <string>

int _tmain(int argc, _TCHAR* argv[])
{
    int x = 42;

    std::string s = std::to_string( x );
}

Product Language

Russian

Operating System

Windows 7

Operating System Language

Russian

Actual results

Errors

error C2668: std::to_string: неоднозначный вызов перегруженной функции
1>         c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(688): может быть "std::string std::to_string(long double)"
1>         c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(680): или     "std::string std::to_string(_ULonglong)"
1>         c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(672): или     "std::string std::to_string(_Longlong)"
1>         при попытке сопоставить список аргументов "(int)"
может быть "std::string std::to_string(long double)"
1>         c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(680): или     "std::string std::to_string(_ULonglong)"
1>         c:\program files (x86)\microsoft visual studio 10.0\vc\include\string(672): или     "std::string std::to_string(_Longlong)"
1>         при попытке сопоставить список аргументов "(int)"

Expected results

The code shall be successfully compiled.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 5/29/2012 at 7:54 PM
Hi,

Thanks for reporting this bug. We've already fixed it, and the fix will be available in VC11 RTM.

You may be interested to learn that this bug was caused by VC10 following an earlier version of the C++0x Working Paper, which specified too few overloads for to_string(). This was fixed in the final version of the C++11 Standard, and we've changed VC11's implementation accordingly.

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by MS-Moderator08 [Feedback Moderator] on 5/20/2012 at 7:53 PM
Thank you for submitting feedback on Visual Studio 11 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 5/18/2012 at 4:44 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.