From ed70349f2742e49d5c037c8fd62cb5fac0b94ece Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Sat, 1 Feb 2020 21:27:53 +0100 Subject: [PATCH] P1423R3 char8_t compatibility remedies (#470) Deletes stream insertion operators for `ostream` with non-`char` character types, and for `wostream` with `charX_t` character types. The `char8_t` operators are deleted in all language modes, but the others are C++20-only to avoid gratuitous breakage (with escape hatch `_HAS_STREAM_INSERTIONS_REMOVED_IN_CXX20`). Skips libc++ tests that expect the pre-P1423R3 value of `__cpp_lib_char8_t`. Resolves #59. --- stl/inc/ostream | 44 ++++++++++++++++++++++++++++++---- stl/inc/yvals_core.h | 9 ++++++- tests/libcxx/skipped_tests.txt | 7 ++++++ 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index d335116da..c064fff67 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -912,14 +912,48 @@ basic_ostream& operator<<( } #ifdef __cpp_char8_t // These deleted overloads are specified in P1423. +// don't insert a UTF-8 NTBS template -basic_ostream& operator<<( - basic_ostream&, const char8_t*) = delete; // don't insert a UTF-8 NTBS +basic_ostream& operator<<(basic_ostream&, const char8_t*) = delete; +template +basic_ostream& operator<<(basic_ostream&, const char8_t*) = delete; + +// don't insert a UTF-8 code unit +template +basic_ostream& operator<<(basic_ostream&, char8_t) = delete; +template +basic_ostream& operator<<(basic_ostream&, char8_t) = delete; +#endif // __cpp_char8_t + +#if !_HAS_STREAM_INSERTION_OPERATORS_DELETED_IN_CXX20 +#ifdef _NATIVE_WCHAR_T_DEFINED +template +basic_ostream& operator<<(basic_ostream&, wchar_t) = delete; template -basic_ostream& operator<<( - basic_ostream&, char8_t) = delete; // don't insert a UTF-8 code unit -#endif // __cpp_char8_t +basic_ostream& operator<<(basic_ostream&, const wchar_t*) = delete; +#endif // _NATIVE_WCHAR_T_DEFINED + +template +basic_ostream& operator<<(basic_ostream&, char16_t) = delete; +template +basic_ostream& operator<<(basic_ostream&, char32_t) = delete; + +template +basic_ostream& operator<<(basic_ostream&, char16_t) = delete; +template +basic_ostream& operator<<(basic_ostream&, char32_t) = delete; + +template +basic_ostream& operator<<(basic_ostream&, const char16_t*) = delete; +template +basic_ostream& operator<<(basic_ostream&, const char32_t*) = delete; + +template +basic_ostream& operator<<(basic_ostream&, const char16_t*) = delete; +template +basic_ostream& operator<<(basic_ostream&, const char32_t*) = delete; +#endif // !_HAS_STREAM_INSERTION_OPERATORS_DELETED_IN_CXX20 template struct _Can_stream_out : false_type {}; diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 1a4d10e40..31eba49fb 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -173,6 +173,7 @@ // P1227R2 Signed std::ssize(), Unsigned span::size() // P1357R1 is_bounded_array, is_unbounded_array // P1394R4 Range Constructor For span +// P1423R3 char8_t Backward Compatibility Remediation // P1456R1 Move-Only Views // P1612R1 Relocating endian To // P1645R1 constexpr For Algorithms @@ -586,6 +587,12 @@ #endif // _M_FP_EXCEPT #endif // _STD_VECTORIZE_WITH_FLOAT_CONTROL +// P1423R3 char8_t Backward Compatibility Remediation +// Controls whether we allow the stream insertions this proposal forbids +#ifndef _HAS_STREAM_INSERTION_OPERATORS_DELETED_IN_CXX20 +#define _HAS_STREAM_INSERTION_OPERATORS_DELETED_IN_CXX20 (!_HAS_CXX20) +#endif // _HAS_STREAM_INSERTION_OPERATORS_DELETED_IN_CXX20 + // P0174R2 Deprecating Vestigial Library Parts // P0521R0 Deprecating shared_ptr::unique() // Other C++17 deprecation warnings @@ -1008,7 +1015,7 @@ #define __cpp_lib_bounded_array_traits 201902L #ifdef __cpp_char8_t -#define __cpp_lib_char8_t 201811L +#define __cpp_lib_char8_t 201907L #endif // __cpp_char8_t #if defined(__cpp_concepts) && __cpp_concepts > 201507L diff --git a/tests/libcxx/skipped_tests.txt b/tests/libcxx/skipped_tests.txt index 06d1868ba..d22aec74a 100644 --- a/tests/libcxx/skipped_tests.txt +++ b/tests/libcxx/skipped_tests.txt @@ -51,6 +51,13 @@ containers\unord\unord.set\insert_and_emplace_allocator_requirements.pass.cpp # See https://reviews.llvm.org/D73138 containers\views\span.sub\subspan.pass.cpp +# libcxx doesn't yet implement P1423R3, so it expects an "old" value for __cpp_lib_char8_t +language.support\support.limits\support.limits.general\filesystem.version.pass.cpp +language.support\support.limits\support.limits.general\istream.version.pass.cpp +language.support\support.limits\support.limits.general\limits.version.pass.cpp +language.support\support.limits\support.limits.general\locale.version.pass.cpp +language.support\support.limits\support.limits.general\ostream.version.pass.cpp + # *** INTERACTIONS WITH CONTEST / C1XX THAT UPSTREAM LIKELY WON'T FIX *** # Tracked by VSO-593630 " Enable libcxx filesystem tests"