|
|
|
|
|
|
| Standard wrote: |
|---|
| 22.4.2.1.2.3 The numeric value to be stored can be one of: — zero, if the conversion function fails to convert the entire field. ios_base::failbit is assigned to err. — the most positive representable value, if the field represents a value too large positive to be represented in val. ios_base::failbit is assigned to err. — the most negative representable value or zero for an unsigned integer type, if the field represents a value too large negative to be represented in val. ios_base::failbit is assigned to err. — the converted value, otherwise. The resultant numeric value is stored in val. |
| The sequence of chars accumulated in stage 2 (the field) is converted to a numeric value by the rules of one of the functions declared in the header <cstdlib>: — For a signed integer value, the function strtoll. — For an unsigned integer value, the function strtoull. — For a floating-point value, the function strtold. |
strtoull cannot possible return negative value. C standard on strtoull is prone to misreading as it seems but it looks like implementation defined result of negating of positive part should be returned. Still, | the most positive representable value, if the field represents a value too large positive to be represented in val. ios_base::failbit is assigned to err. |
| suitably adjusted to ensure static type safety |
| The sequence of chars accumulated in stage 2 (the field) |
| converted to a numeric value by ... the function strtoull. |
| The numeric value to be stored ... the most negative representable value or zero for an unsigned integer type, if the field represents a value too large negative to be represented in val. ios_base::failbit is assigned to err. |
|
|
echo 'clang++ libc++' && clang++ -std=c++14 -stdlib=libc++ -O2 -Wall -Wextra -pedantic-errors main.cpp -lsupc++ && ./a.out <<< -1test echo -e '\ng++ libstdc++' && g++ -std=c++14 -O2 -Wall -Wextra -pedantic-errors main.cpp && ./a.out <<< -1test clang++ libc++ std::cin >> u input failure: value was set to 0 the string read is: test g++ libstdc++ std::cin >> u success: value 4294967295 was read the string read is: test |
| On the other hand, the result of num_get conversion of negative values to unsigned integer types is zero. This raises a compatibility issue. ... THe issues is what to do with -1. Should it match 'C' or do the "sane" thing. |