This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++14 status.
Section: 27.4.5[string.conversions]Status:C++14Submitter: Alisdair MeredithOpened: 2010-07-19Last modified: 2016-01-28
Priority:Not Prioritized
View all otherissues in [string.conversions].
View all issues withC++14 status.
Discussion:
The functions (w)stoi and (w)stofare specified in terms of calling C library APIs for potentially widertypes. The integer and floating-point versions have subtly differentbehaviour when reading values that are too large to convert. Thefloating point case will throwout_of_bound if the read valueis too large to convert to the wider type used in the implementation,but behaviour is undefined if the converted value cannot narrow to afloat. The integer case will throwout_of_bounds if theconverted value cannot be represented in the narrower type, but throwsinvalid_argument, rather thanout_of_range, if theconversion to the wider type fails due to overflow.
Suggest that the Throws clause for both specifications should beconsistent, supporting the same set of fail-modes with the matching setof exceptions.
Proposed resolution:
21.5p3 [string.conversions]
int stoi(const string& str, size_t *idx = 0, int base = 10);long stol(const string& str, size_t *idx = 0, int base = 10);unsigned long stoul(const string& str, size_t *idx = 0, int base = 10);long long stoll(const string& str, size_t *idx = 0, int base = 10);unsigned long long stoull(const string& str, size_t *idx = 0, int base = 10);...
3Throws:
invalid_argumentifstrtol,strtoul,strtoll, orstrtoullreports that noconversion could be performed. Throwsout_of_rangeifstrtol,strtoul,strtollorstrtoullsetserrnotoERANGE, or ifthe converted value is outside the range of representable values for thereturn type.
21.5p6 [string.conversions]
float stof(const string& str, size_t *idx = 0);double stod(const string& str, size_t *idx = 0);long double stold(const string& str, size_t *idx = 0);...
6Throws:
invalid_argumentifstrtodorstrtoldreports that no conversion could be performed. Throwsout_of_rangeifstrtodorstrtoldsetserrnotoERANGEor if the converted value isoutside the range of representable values for the return type.