Home Dashboard Directory Help

[C++0X] std::to_string is non conforming by Thomas Petit



Sign in
to vote
Type: Bug
ID: 576750
Opened: 7/20/2010 11:32:09 AM
Access Restriction: Public
User(s) can reproduce this bug


std::to_string from <string> provides only three overloads : long double, long long and unsigned long long, and thus fail on super simple case :

int i = 5;
std::string s = std::to_string(i);

error C2668: 'std::to_string' : ambiguous call to overloaded function

As per resolution of DR 1261, the current C++ standard draft mandates that std::to_string provide the full range of overload (int, unsigned int, long, unsigned long, long long, unsigned long long, float , double, long double) to avoid this kind of trouble.

See also : http://gcc.gnu.org/ml/libstdc++/2009-11/msg00026.html
Sign in to post a comment.
Posted by Microsoft on 1/9/2012 at 2:21 PM
We also fixed to_wstring().

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Alessio T on 1/9/2012 at 2:03 PM
hi, the same issue affects also the wstring version std::to_wstring
Posted by Microsoft on 8/25/2011 at 10:13 AM
Sorry, this fix wasn't in VC10 SP1. Only severe runtime bugs are candidates for being fixed in a service pack. As obnoxious as the C++0x Working Paper's earlier specification of to_string() was, it causes problems at compiletime only.

(Note that I'm not automatically notified when people comment on bugs, especially resolved bugs; you must E-mail me to get my attention. I happened to notice this comment by chance.)

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Andrew McDonald on 2/3/2011 at 7:25 AM
Is there any chance this will be in VS2010 SP1?
Posted by Microsoft on 11/1/2010 at 3:47 AM

Thanks for reporting this bug. We've fixed it by implementing the additional overloads of to_string() that were recently added to the C++0x Working Paper, and the fix will be in VC11.

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 Microsoft on 7/21/2010 at 12:04 AM
Thank you for reporting the issue.
We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.These specialized experts will follow-up with your issue.
Posted by Microsoft on 7/20/2010 at 5:05 PM
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.
Posted by Thomas Petit on 7/20/2010 at 12:38 PM
Cast to the largest appropriate type :

int i = 5;
std::string s1 = std::to_string((long long)i);

float f = 5.0f;
std::string s2 = std::to_string((long double)f);