| Issue |
87969
|
| Summary |
[libc++] `num_get::get` extracts too many characters when the input is invalid
|
| Labels |
libc++
|
| Assignees |
|
| Reporter |
frederick-vs-ja
|
Currently, the following program prints 2 when using libc++, which means that the call to `num_get::get` accumulates the whole "XX" when parsing a `double` value ([Godbolt link](https://godbolt.org/z/v9Web7f6G)).
```C++
#include <iostream>
#include <sstream>
#include <locale>
int main()
{
struct num_get_helper : std::num_get<char, char*> {};
num_get_helper ng;
char str[]{"XX"};
std::ios_base::iostate err{};
double x = -1.0;
std::istringstream is;
auto it = ng.get(str, str + sizeof(str) - 1, is, err, x);
std::cout << it - str << '\n';
}
```
Per [[facet.num.get.virtuals]](https://eel.is/c++draft/facet.num.get.virtuals#3):
> If it is not discarded, then a check is made to determine if `c` is allowed as the next character of an input field of the conversion specifier returned by Stage 1.
The leading 'X' is already a disallowed character for specifier `l` (for `double`), so it shouldn't be accumulated and thus the printed value should be 0.
Likewise, if `"XX"` is replaced with `"0XX"`, the printed value should be 2 ('0' and the first 'X' are accumulated), but libc++ currently reports 3 ([Godbolt link](https://godbolt.org/z/6d69dscha)).
It seems that some checking for being "allowed as the next character of an input field of the conversion specifier" is missing.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs