Skip to content

[libcxx] operator>>(integer) consumes too much input characters when basefield == 0 #158102

@morinmorin

Description

@morinmorin

When basefield == 0, __stage2_int_loop in num.h does not distinguish 'x'/'X' from digit characters (0–9, a–f, A–F). As a result, reading from "10xFFx01" (with basefield == 0) consumes the whole input.

Testcase:

#include <iostream>
#include <iomanip>
#include <sstream>

int main()
{
    std::istringstream is("10xFFx0.1=FF");
    int x;

    is >> std::setbase(0);
    is >> x;
    bool failbit = is.fail();
    if (failbit) is.clear();
    auto next_pos = is.tellg();

    std::cout << "value: " << x << '\n'; // expected: 10, actual: 0
    std::cout << "fail: " << failbit << '\n'; // expected: 0, actual: 1
    std::cout << "next: " << next_pos << '\n'; // expected: 2 (1st 'x'), actual: 7 ('.')
}

It looks like PR #121795 fixes this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.localeissues related to localization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions