Skip to content
This repository has been archived by the owner. It is now read-only.

std::basic_stringstream is not working with std::byte #40270

Closed
hanickadot mannequin opened this issue Jan 9, 2019 · 4 comments
Closed

std::basic_stringstream is not working with std::byte #40270

hanickadot mannequin opened this issue Jan 9, 2019 · 4 comments

Comments

@hanickadot
Copy link
Mannequin

@hanickadot hanickadot mannequin commented Jan 9, 2019

Bugzilla Link 40270
Resolution INVALID
Resolved on Jan 13, 2019 10:03
Version 7.0
OS MacOS X
Attachments source code to emit the error
CC @mclow

Extended Description

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.

@hanickadot
Copy link
Mannequin Author

@hanickadot hanickadot mannequin commented Jan 9, 2019

assigned to @mclow

Loading

@mclow
Copy link

@mclow mclow commented 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.

Loading

@hanickadot
Copy link
Mannequin Author

@hanickadot hanickadot mannequin commented Jan 9, 2019

Thank you, will report everything I found with std::byte (string) streams.

Loading

@mclow
Copy link

@mclow mclow commented 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.

Loading

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant