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

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

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

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

hanickadot opened this issue Jan 9, 2019 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla invalid Resolved as invalid, i.e. not a bug libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@hanickadot
Copy link
Contributor

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
Contributor Author

assigned to @mclow

@mclow
Copy link
Contributor

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.

@hanickadot
Copy link
Contributor Author

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

@mclow
Copy link
Contributor

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.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla invalid Resolved as invalid, i.e. not a bug libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

2 participants