Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<bitset>: streaming operator >> does not use character traits #4956

Open
AlexGuteniev opened this issue Sep 13, 2024 · 2 comments
Open

<bitset>: streaming operator >> does not use character traits #4956

AlexGuteniev opened this issue Sep 13, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@AlexGuteniev
Copy link
Contributor

_Char is directly compared against _Elem0 and _Elem1

STL/stl/inc/bitset

Lines 589 to 600 in 73b5791

if (_Tr::eq_int_type(_Tr::eof(), _Meta)) { // end of file, quit
_State |= _Istr_t::eofbit;
break;
} else if ((_Char = _Tr::to_char_type(_Meta)) != _Elem0 && _Char != _Elem1) {
break; // invalid element
} else if (_Str.max_size() <= _Str.size()) { // no room in string, give up (unlikely)
_State |= _Istr_t::failbit;
break;
} else { // valid, append '0' or '1'
_Str.push_back('0' + (_Char == _Elem1));
_Changed = true;
}

@CaseyCarter CaseyCarter added the bug Something isn't working label Sep 13, 2024
@AlexGuteniev
Copy link
Contributor Author

If we want test coverage, we could wait for #4951 and then share significant test part.

@StephanTLavavej
Copy link
Member

We checked, and fortunately bitset's constructor properly implements WG21-N4988 [bitset.cons]/6 "The function uses traits::eq to compare the character values." (here and on other lines):

if (!_Traits::eq(_Elem1, _Ch) && !_Traits::eq(_Elem0, _Ch)) {

So the problem is limited to the streaming operator. We'll grumble a bit that [bitset.operators]/5.3 "the next input character is neither is.widen('0') nor is.widen('1') (in which case the input character is not extracted)" is vague about how "neither" is determined, and this probably deserves an LWG issue, but the intent seems to be clear enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants