[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] Dealing with deleted operator<<() overloads for wide char types in
From: |
Vadim Zeitlin |
Subject: |
[lmi] Dealing with deleted operator<<() overloads for wide char types in C++20 |
Date: |
Thu, 25 Feb 2021 21:55:00 +0100 |
Hello,
As you might already know, C++20 adds deleted operator<<() overloads for
char{8,16,32}_t and wchar_t types to std::basic_ostream. This is a sensible
change, as it prevents unexpected handling of these types in std::ostream,
but it does break compilation of the existing code in a lot of cases and
this includes lmi bourn_cast_test.cpp (just FYI, I had already fixed
wxWidgets that was affected by this too).
For the reference, the exact error message, for the first of the many
errors, is this:
---------------------------------- >8 --------------------------------------
In file included from bourn_cast_test.cpp:54:
bourn_cast_test.cpp: In instantiation of ‘void test_same(const char*, int)
[with T = char16_t]’:
bourn_cast_test.cpp:737:57: required from here
test_tools.hpp:228:22: error: use of deleted function ‘std::basic_ostream<char,
_Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char16_t) [with
_Traits = std::char_traits<char>]’
227 | lmi_test::error_stream() \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228 | << " '" << (a) << "' "#op" '" << (b) << "'" \
| ~~~~~~~~~^~~~~~
test_tools.hpp:216:5: note: in expansion of macro ‘INVOKE_BOOST_TEST_RELATION’
216 | INVOKE_BOOST_TEST_RELATION(a,==,b,file,line) \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
bourn_cast_test.cpp:67:5: note: in expansion of macro ‘INVOKE_BOOST_TEST_EQUAL’
67 | INVOKE_BOOST_TEST_EQUAL(upper, bourn_cast<T>(upper), file, line);
| ^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/bits/unique_ptr.h:42,
from /usr/include/c++/10/bits/locale_conv.h:41,
from /usr/include/c++/10/locale:43,
from /usr/include/c++/10/iomanip:43,
from miscellany.hpp:33,
from bourn_cast_test.cpp:52:
/usr/include/c++/10/ostream:549:5: note: declared here
549 | operator<<(basic_ostream<char, _Traits>&, char16_t) = delete;
| ^~~~~~~~
---------------------------------- >8 --------------------------------------
but it just says in compilese what I wrote above, i.e. that we can't insert
a char16_t value into the stream any more.
There are several ways to solve this, but I wonder if it's even worth
solving it at all, or if we could simply remove test_same() calls for the
char{16,32}_t and wchar_t types in the test? It seems exceedingly unlikely
that bourn_cast() would be used with any of these types and, in fact, I
wonder if we shouldn't just prevent it from being used with them.
What do you think?
VZ
pgpNkkXesAXdw.pgp
Description: PGP signature
- [lmi] Dealing with deleted operator<<() overloads for wide char types in C++20,
Vadim Zeitlin <=