You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
std::basic_stringstream is not working with std::byte #39617
I can't compile std::basic_stringstream<std::byte, ByteCharTraits> with only constructor. GCC accepts this code.
It gives error in basic_stringbuf::allocator on sputc function.
clang++ -stdlib=libc++ byte_stream.cpp -std=c++17
In file included from byte_stream.cpp:1:
/usr/local/Cellar/llvm/7.0.0/include/c++/v1/sstream:562:28: error: cannot initialize a parameter of type 'std::__1::basic_streambuf<std::byte,
ByteCharTraits>::char_type' (aka 'std::byte') with an lvalue of type 'std::__1::basic_stringbuf<std::byte, ByteCharTraits,
std::__1::allocatorstd::byte >::int_type' (aka 'int')
return this->sputc(__c);
^~~
/usr/local/Cellar/llvm/7.0.0/include/c++/v1/sstream:866:28: note: in instantiation of member function 'std::__1::basic_stringbuf<std::byte,
ByteCharTraits, std::__1::allocatorstd::byte >::overflow' requested here
class _LIBCPP_TEMPLATE_VIS basic_stringstream
^
/usr/local/Cellar/llvm/7.0.0/include/c++/v1/streambuf:221:30: note: passing argument to parameter '__c' here
int_type sputc(char_type __c) {
^
1 error generated.
Tanks for the report. I have reproduced this locally; it appears that someone made an assumption that traits::char_type and traits::int_type are implicitly convertible. (which (a) has been true in the past, and (b) is not true for your example).
Fixing this particular bit is straightforward; replace line 562 of with
return this->sputc(traits_type::to_char_type(__c));
However, I'm wondering what other places this assumption is lurking in the iostreams code. I'll be looking into that soon.
In the classes of [input.output], a template parameter with name charT represents a member of the set of types containing char, wchar_t, and any other implementation-defined character types that satisfy the requirements for a character on which any of the iostream components can be instantiated.
Activity
hanickadot commentedon Jan 9, 2019
assigned to @mclow
mclow commentedon Jan 9, 2019
Tanks for the report. I have reproduced this locally; it appears that someone made an assumption that traits::char_type and traits::int_type are implicitly convertible. (which (a) has been true in the past, and (b) is not true for your example).
Fixing this particular bit is straightforward; replace line 562 of with
return this->sputc(traits_type::to_char_type(__c));
However, I'm wondering what other places this assumption is lurking in the iostreams code. I'll be looking into that soon.
hanickadot commentedon Jan 9, 2019
Thank you, will report everything I found with std::byte (string) streams.
mclow commentedon Jan 13, 2019
Billy O'Neil commented on twitter: (https://twitter.com/MalwareMinigun/status/1083420061069496322)
and noted that http://eel.is/c++draft/iostreams.limits.pos#2 says:
In the classes of [input.output], a template parameter with name charT represents a member of the set of types containing char, wchar_t, and any other implementation-defined character types that satisfy the requirements for a character on which any of the iostream components can be instantiated.
Since byte is not a character type (http://eel.is/c++draft/basic.fundamental#7), so you don't get streams of std::byte.