Skip to content

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

Closed

Description

@hanickadot
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.

Activity

  1. hanickadot commented on Jan 9, 2019

    @hanickadot
    ContributorAuthor

    assigned to @mclow

  2. mclow commented on Jan 9, 2019

    @mclow
    Contributor

    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.

  3. hanickadot commented on Jan 9, 2019

    @hanickadot
    ContributorAuthor

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

  4. mclow commented on Jan 13, 2019

    @mclow
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillainvalidResolved as invalid, i.e. not a buglibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions