[libc++] Implement P1423R3 (char8_t backward compatibility remediation)

Reviewed By: Mordante, #libc

Spies: h-vetinari, libcxx-commits, arichardson

Differential Revision: https://reviews.llvm.org/D129195
This commit is contained in:
Nikolas Klauser 2022-07-19 02:03:10 +02:00
parent 20d30f709b
commit 309aed3068
16 changed files with 186 additions and 50 deletions

View File

@ -196,7 +196,7 @@ Status
------------------------------------------------- -----------------
``__cpp_lib_bounded_array_traits`` ``201902L``
------------------------------------------------- -----------------
``__cpp_lib_char8_t`` ``201811L``
``__cpp_lib_char8_t`` ``201907L``
------------------------------------------------- -----------------
``__cpp_lib_concepts`` ``202002L``
------------------------------------------------- -----------------

View File

@ -49,6 +49,7 @@ Implemented Papers
- P0618R0 (Deprecating <codecvt>)
- P2418R2 (Add support for ``std::generator``-like types to ``std::format``)
- LWG3659 (Consider ``ATOMIC_FLAG_INIT`` undeprecation)
- P1423R3 (char8_t backward compatibility remediation)
- Marked the following papers as "Complete" (note that some of those might have
been implemented in a previous release but not marked as such):

View File

@ -115,7 +115,7 @@
"`P1208R6 <https://wg21.link/P1208R6>`__","LWG","Adopt source_location for C++20","Cologne","",""
"`P1355R2 <https://wg21.link/P1355R2>`__","LWG","Exposing a narrow contract for ceil2","Cologne","|Complete|","9.0"
"`P1361R2 <https://wg21.link/P1361R2>`__","LWG","Integration of chrono with text formatting","Cologne","",""
"`P1423R3 <https://wg21.link/P1423R3>`__","LWG","char8_t backward compatibility remediation","Cologne","|In Progress|",""
"`P1423R3 <https://wg21.link/P1423R3>`__","LWG","char8_t backward compatibility remediation","Cologne","|Complete|","15.0"
"`P1424R1 <https://wg21.link/P1424R1>`__","LWG","'constexpr' feature macro concerns","Cologne","Superseded by `P1902 <https://wg21.link/P1902>`__",""
"`P1466R3 <https://wg21.link/P1466R3>`__","LWG","Miscellaneous minor fixes for chrono","Cologne","",""
"`P1474R1 <https://wg21.link/P1474R1>`__","LWG","Helpful pointers for ContiguousIterator","Cologne","|Complete|","15.0"

1 Paper # Group Paper Name Meeting Status First released version
115 `P1208R6 <https://wg21.link/P1208R6>`__ LWG Adopt source_location for C++20 Cologne
116 `P1355R2 <https://wg21.link/P1355R2>`__ LWG Exposing a narrow contract for ceil2 Cologne |Complete| 9.0
117 `P1361R2 <https://wg21.link/P1361R2>`__ LWG Integration of chrono with text formatting Cologne
118 `P1423R3 <https://wg21.link/P1423R3>`__ LWG char8_t backward compatibility remediation Cologne |In Progress| |Complete| 15.0
119 `P1424R1 <https://wg21.link/P1424R1>`__ LWG 'constexpr' feature macro concerns Cologne Superseded by `P1902 <https://wg21.link/P1902>`__
120 `P1466R3 <https://wg21.link/P1466R3>`__ LWG Miscellaneous minor fixes for chrono Cologne
121 `P1474R1 <https://wg21.link/P1474R1>`__ LWG Helpful pointers for ContiguousIterator Cologne |Complete| 15.0

View File

@ -130,6 +130,35 @@ template <class charT, class traits>
template <class Stream, class T>
Stream&& operator<<(Stream&& os, const T& x);
template<class traits>
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, wchar_t) = delete; // since C++20
template<class traits>
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char8_t) = delete; // since C++20
template<class traits>
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char16_t) = delete; // since C++20
template<class traits>
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, char32_t) = delete; // since C++20
template<class traits>
basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char8_t) = delete; // since C++20
template<class traits>
basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char16_t) = delete; // since C++20
template<class traits>
basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, char32_t) = delete; // since C++20
template<class traits>
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const wchar_t*) = delete; // since C++20
template<class traits>
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char8_t*) = delete; // since C++20
template<class traits>
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char16_t*) = delete; // since C++20
template<class traits>
basic_ostream<char, traits>& operator<<(basic_ostream<char, traits>&, const char32_t*) = delete; // since C++20
template<class traits>
basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char8_t*) = delete; // since C++20
template<class traits>
basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char16_t*) = delete; // since C++20
template<class traits>
basic_ostream<wchar_t, traits>& operator<<(basic_ostream<wchar_t, traits>&, const char32_t*) = delete; // since C++20
} // std
*/
@ -1102,6 +1131,57 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
}
#if _LIBCPP_STD_VER > 17
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
template <class _Traits>
basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, wchar_t) = delete;
template <class _Traits>
basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const wchar_t*) = delete;
template <class _Traits>
basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char16_t) = delete;
template <class _Traits>
basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char32_t) = delete;
template <class _Traits>
basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char16_t*) = delete;
template <class _Traits>
basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char32_t*) = delete;
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
#ifndef _LIBCPP_HAS_NO_CHAR8_T
template <class _Traits>
basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char8_t) = delete;
template <class _Traits>
basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, char8_t) = delete;
template <class _Traits>
basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char8_t*) = delete;
template <class _Traits>
basic_ostream<wchar_t, _Traits>& operator<<(basic_ostream<wchar_t, _Traits>&, const char8_t*) = delete;
#endif
template <class _Traits>
basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char16_t) = delete;
template <class _Traits>
basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, char32_t) = delete;
template <class _Traits>
basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char16_t*) = delete;
template <class _Traits>
basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>&, const char32_t*) = delete;
#endif // _LIBCPP_STD_VER > 17
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>;
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>;

View File

@ -47,7 +47,7 @@ __cpp_lib_bounded_array_traits 201902L <type_traits>
__cpp_lib_boyer_moore_searcher 201603L <functional>
__cpp_lib_byte 201603L <cstddef>
__cpp_lib_byteswap 202110L <bit>
__cpp_lib_char8_t 201811L <atomic> <filesystem> <istream>
__cpp_lib_char8_t 201907L <atomic> <filesystem> <istream>
<limits> <locale> <ostream>
<string> <string_view>
__cpp_lib_chrono 201611L <chrono>
@ -308,7 +308,7 @@ __cpp_lib_void_t 201411L <type_traits>
// # define __cpp_lib_bitops 201907L
# define __cpp_lib_bounded_array_traits 201902L
# if !defined(_LIBCPP_HAS_NO_CHAR8_T)
# define __cpp_lib_char8_t 201811L
# define __cpp_lib_char8_t 201907L
# endif
# define __cpp_lib_concepts 202002L
# define __cpp_lib_constexpr_algorithms 201806L

View File

@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// <ostream>
#include <ostream>
#include <sstream>
#include <utility>
#include "test_macros.h"
int main() {
std::ostringstream s;
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
s << wchar_t(); // expected-error {{overload resolution selected deleted operator '<<'}}
s << std::declval<wchar_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
s << std::declval<const wchar_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
std::wostringstream sw;
# ifndef TEST_HAS_NO_CHAR8_T
sw << char8_t(); // expected-error {{overload resolution selected deleted operator '<<'}}
sw << std::declval<char8_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
sw << std::declval<const char8_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
# endif
sw << char16_t(); // expected-error {{overload resolution selected deleted operator '<<'}}
sw << std::declval<char16_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
sw << std::declval<const char16_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
sw << char32_t(); // expected-error {{overload resolution selected deleted operator '<<'}}
sw << std::declval<char32_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
sw << std::declval<const char32_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
#endif // TEST_HAS_NO_WIDE_CHARACTERS
#ifndef TEST_HAS_NO_CHAR8_T
s << char8_t(); // expected-error {{overload resolution selected deleted operator '<<'}}
s << std::declval<char8_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
s << std::declval<const char8_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
#endif
s << char16_t(); // expected-error {{overload resolution selected deleted operator '<<'}}
s << std::declval<char16_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
s << std::declval<const char16_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
s << char32_t(); // expected-error {{overload resolution selected deleted operator '<<'}}
s << std::declval<char32_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
s << std::declval<const char32_t*>(); // expected-error {{overload resolution selected deleted operator '<<'}}
}

View File

@ -24,7 +24,7 @@
__cpp_lib_atomic_shared_ptr 201711L [C++20]
__cpp_lib_atomic_value_initialization 201911L [C++20]
__cpp_lib_atomic_wait 201907L [C++20]
__cpp_lib_char8_t 201811L [C++20]
__cpp_lib_char8_t 201907L [C++20]
*/
#include <atomic>
@ -233,8 +233,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++20"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++20"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++20"
# endif
# else
# ifdef __cpp_lib_char8_t
@ -328,8 +328,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++2b"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++2b"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++2b"
# endif
# else
# ifdef __cpp_lib_char8_t

View File

@ -18,7 +18,7 @@
// Test the feature test macros defined by <filesystem>
/* Constant Value
__cpp_lib_char8_t 201811L [C++20]
__cpp_lib_char8_t 201907L [C++20]
__cpp_lib_filesystem 201703L [C++17]
*/
@ -70,8 +70,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++20"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++20"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++20"
# endif
# else
# ifdef __cpp_lib_char8_t
@ -98,8 +98,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++2b"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++2b"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++2b"
# endif
# else
# ifdef __cpp_lib_char8_t

View File

@ -18,7 +18,7 @@
// Test the feature test macros defined by <istream>
/* Constant Value
__cpp_lib_char8_t 201811L [C++20]
__cpp_lib_char8_t 201907L [C++20]
*/
#include <istream>
@ -48,8 +48,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++20"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++20"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++20"
# endif
# else
# ifdef __cpp_lib_char8_t
@ -63,8 +63,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++2b"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++2b"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++2b"
# endif
# else
# ifdef __cpp_lib_char8_t

View File

@ -16,7 +16,7 @@
// Test the feature test macros defined by <limits>
/* Constant Value
__cpp_lib_char8_t 201811L [C++20]
__cpp_lib_char8_t 201907L [C++20]
*/
#include <limits>
@ -46,8 +46,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++20"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++20"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++20"
# endif
# else
# ifdef __cpp_lib_char8_t
@ -61,8 +61,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++2b"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++2b"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++2b"
# endif
# else
# ifdef __cpp_lib_char8_t

View File

@ -18,7 +18,7 @@
// Test the feature test macros defined by <locale>
/* Constant Value
__cpp_lib_char8_t 201811L [C++20]
__cpp_lib_char8_t 201907L [C++20]
*/
#include <locale>
@ -48,8 +48,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++20"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++20"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++20"
# endif
# else
# ifdef __cpp_lib_char8_t
@ -63,8 +63,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++2b"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++2b"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++2b"
# endif
# else
# ifdef __cpp_lib_char8_t

View File

@ -18,7 +18,7 @@
// Test the feature test macros defined by <ostream>
/* Constant Value
__cpp_lib_char8_t 201811L [C++20]
__cpp_lib_char8_t 201907L [C++20]
*/
#include <ostream>
@ -48,8 +48,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++20"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++20"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++20"
# endif
# else
# ifdef __cpp_lib_char8_t
@ -63,8 +63,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++2b"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++2b"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++2b"
# endif
# else
# ifdef __cpp_lib_char8_t

View File

@ -17,7 +17,7 @@
/* Constant Value
__cpp_lib_allocator_traits_is_always_equal 201411L [C++17]
__cpp_lib_char8_t 201811L [C++20]
__cpp_lib_char8_t 201907L [C++20]
__cpp_lib_constexpr_string 201907L [C++20]
__cpp_lib_erase_if 202002L [C++20]
__cpp_lib_nonmember_container_access 201411L [C++17]
@ -199,8 +199,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++20"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++20"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++20"
# endif
# else
# ifdef __cpp_lib_char8_t
@ -275,8 +275,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++2b"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++2b"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++2b"
# endif
# else
# ifdef __cpp_lib_char8_t

View File

@ -16,7 +16,7 @@
// Test the feature test macros defined by <string_view>
/* Constant Value
__cpp_lib_char8_t 201811L [C++20]
__cpp_lib_char8_t 201907L [C++20]
__cpp_lib_constexpr_string_view 201811L [C++20]
__cpp_lib_starts_ends_with 201711L [C++20]
__cpp_lib_string_contains 202011L [C++2b]
@ -102,8 +102,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++20"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++20"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++20"
# endif
# else
# ifdef __cpp_lib_char8_t
@ -142,8 +142,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++2b"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++2b"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++2b"
# endif
# else
# ifdef __cpp_lib_char8_t

View File

@ -45,7 +45,7 @@
__cpp_lib_boyer_moore_searcher 201603L [C++17]
__cpp_lib_byte 201603L [C++17]
__cpp_lib_byteswap 202110L [C++2b]
__cpp_lib_char8_t 201811L [C++20]
__cpp_lib_char8_t 201907L [C++20]
__cpp_lib_chrono 201611L [C++17]
__cpp_lib_chrono_udls 201304L [C++14]
__cpp_lib_clamp 201603L [C++17]
@ -2595,8 +2595,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++20"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++20"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++20"
# endif
# else
# ifdef __cpp_lib_char8_t
@ -3814,8 +3814,8 @@
# ifndef __cpp_lib_char8_t
# error "__cpp_lib_char8_t should be defined in c++2b"
# endif
# if __cpp_lib_char8_t != 201811L
# error "__cpp_lib_char8_t should have the value 201811L in c++2b"
# if __cpp_lib_char8_t != 201907L
# error "__cpp_lib_char8_t should have the value 201907L in c++2b"
# endif
# else
# ifdef __cpp_lib_char8_t

View File

@ -186,7 +186,7 @@ feature_test_macros = [ add_version_header(x) for x in [
"headers": ["bit"],
}, {
"name": "__cpp_lib_char8_t",
"values": { "c++20": 201811 },
"values": { "c++20": 201907 },
"headers": ["atomic", "filesystem", "istream", "limits", "locale", "ostream", "string", "string_view"],
"test_suite_guard": "defined(__cpp_char8_t)",
"libcxx_guard": "!defined(_LIBCPP_HAS_NO_CHAR8_T)",