[Bug libstdc++/88508] New: std::bad_cast in std::basic_ostringstream<char16_t>.oss.fill()
dudin.roman at list dot ru
gcc-bugzilla@gcc.gnu.org
Sat Dec 15 01:55:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88508
Bug ID: 88508
Summary: std::bad_cast in
std::basic_ostringstream<char16_t>.oss.fill()
Product: gcc
Version: 8.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: dudin.roman at list dot ru
Target Milestone: ---
Created attachment 45241
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45241&action=edit
Code
I am trying to add support of UTF-16 and UTF-32 in C++17 environment.
Short fragment of my code:
namespace std {
typedef basic_ostringstream<char16_t> u16ostringstream;
}
std::u16string to_hexdump_u16(const std::u16string_view &str_v) {
std::u16ostringstream oss;
oss.setf(std::ios::hex, std::ios::basefield);
oss.fill(u'0');
...
return oss.str();
}
int main() {
auto str_u16 = u"Hello, my favorite World with native UTF-16 & UTF-32
support!♥❤♡";
auto str_dump_u16 = to_hexdump_u16(str_u16);
return 0;
}
I compile it via CMake with set(CMAKE_CXX_STANDARD 17)
It compiles successfully, but the bad_cast exception occurs when
"oss.fill(u'0')" is called. The internal function which throws the exception is
"__check_facet(const _Facet* __f)" in basic_ios.h.
Exception is also thrown when calling "oss << std::endl", but I think it's the
same problem.
Problem touches latest library compiled with clang (linux), gcc 8.1 (mingw-w64,
linux). The code compiles and works fine on latest MSVC compiler.
The one-file full example in attach.
More information about the Gcc-bugs
mailing list