1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-30 12:04:07 +00:00

Vendor import of libc++ trunk r303197:

https://llvm.org/svn/llvm-project/libcxx/trunk@303197
This commit is contained in:
Dimitry Andric 2017-05-16 19:47:31 +00:00
parent 733153a0fb
commit 7582e3938b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/libc++/dist/; revision=318374
svn path=/vendor/libc++/libc++-trunk-r303197/; revision=318375; tag=vendor/libc++/libc++-trunk-r303197
106 changed files with 1946 additions and 2180 deletions

View File

@ -1,11 +1,12 @@
@echo on
if NOT EXIST C:\projects\deps (
mkdir C:\projects\deps
)
cd C:\projects\deps
::###########################################################################
:: Setup the path to Clang-cl
:: Setup Compiler
::###########################################################################
if NOT EXIST llvm-installer.exe (
appveyor DownloadFile http://llvm.org/pre-releases/win-snapshots/LLVM-5.0.0-r301646-win32.exe -FileName llvm-installer.exe
@ -13,8 +14,13 @@ if NOT EXIST llvm-installer.exe (
if "%CLANG_VERSION%"=="ToT" (
START /WAIT llvm-installer.exe /S /D=C:\"Program Files\LLVM"
)
@set PATH="C:\Program Files\LLVM\bin";%PATH%
clang-cl -v
if DEFINED CLANG_VERSION @set PATH="C:\Program Files\LLVM\bin";%PATH%
if DEFINED CLANG_VERSION clang-cl -v
if DEFINED MINGW_PATH rename "C:\Program Files\Git\usr\bin\sh.exe" "sh-ignored.exe"
if DEFINED MINGW_PATH @set "PATH=%PATH:C:\Program Files (x86)\Git\bin=%"
if DEFINED MINGW_PATH @set "PATH=%PATH%;%MINGW_PATH%"
if DEFINED MINGW_PATH g++ -v
::###########################################################################
:: Install a recent CMake

View File

@ -11,24 +11,35 @@ configuration:
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_OPTIONS: -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe
CLANG_VERSION: ToT
MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat
MSVC_SETUP_ARG: x86
GENERATOR: Ninja
MAKE_PROGRAM: ninja
APPVEYOR_SAVE_CACHE_ON_ERROR: true
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE_OPTIONS: -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe
CLANG_VERSION: 4
MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
MSVC_SETUP_ARG: x86_amd64
GENERATOR: Ninja
MAKE_PROGRAM: ninja
APPVEYOR_SAVE_CACHE_ON_ERROR: true
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
MINGW_PATH: C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev1\mingw32\bin
GENERATOR: MinGW Makefiles
MAKE_PROGRAM: mingw32-make
APPVEYOR_SAVE_CACHE_ON_ERROR: true
install:
############################################################################
# All external dependencies are installed in C:\projects\deps
############################################################################
- call "%APPVEYOR_BUILD_FOLDER%\\install-appveyor-reqs.cmd"
- call "%APPVEYOR_BUILD_FOLDER%\\appveyor-reqs-install.cmd"
before_build:
- call "%MSVC_SETUP_PATH%" %MSVC_SETUP_ARG%
- if DEFINED MSVC_SETUP_PATH call "%MSVC_SETUP_PATH%" %MSVC_SETUP_ARG%
- cd %APPVEYOR_BUILD_FOLDER%
build_script:
@ -39,8 +50,7 @@ build_script:
#############################################################################
# Configuration Step
#############################################################################
- cmake -G Ninja %extra_cmake_flags%
-DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe
- cmake -G "%GENERATOR%" %CMAKE_OPTIONS%
"-DCMAKE_BUILD_TYPE=%configuration%"
"-DLLVM_PATH=C:\projects\deps\llvm" -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF
-DLLVM_LIT_ARGS="-sv --show-xfail --show-unsupported"
@ -49,10 +59,10 @@ build_script:
#############################################################################
# Build Step
#############################################################################
- ninja
- "%MAKE_PROGRAM%"
test_script:
- ninja check-cxx
- "%MAKE_PROGRAM% check-cxx"
on_failure:
- appveyor PushArtifact CMakeFiles/CMakeOutput.log

View File

@ -1,9 +1,9 @@
if (LLVM_ENABLE_SPHINX)
include(AddSphinxTarget)
if (SPHINX_FOUND)
include(AddSphinxTarget)
if (${SPHINX_OUTPUT_HTML})
add_sphinx_target(html libcxx)
endif()
endif()
endif()
endif()

View File

@ -119,7 +119,7 @@ configuration. Passing the option on the command line will override the default.
.. option:: libcxx_site_config=<path/to/lit.site.cfg>
Specify the site configuration to use when running the tests. This option
overrides the enviroment variable LIBCXX_SITE_CONFIG.
overrides the environment variable LIBCXX_SITE_CONFIG.
.. option:: cxx_headers=<path/to/headers>

View File

@ -19,27 +19,24 @@
_LIBCPP_BEGIN_NAMESPACE_STD
typedef _VSTD::remove_pointer<locale_t>::type __use_locale_struct;
typedef _VSTD::unique_ptr<__use_locale_struct, decltype(&uselocale)> __locale_raii;
inline _LIBCPP_ALWAYS_INLINE
decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
{
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
return MB_CUR_MAX;
}
inline _LIBCPP_ALWAYS_INLINE
wint_t __libcpp_btowc_l(int __c, locale_t __l)
{
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
return btowc(__c);
}
inline _LIBCPP_ALWAYS_INLINE
int __libcpp_wctob_l(wint_t __c, locale_t __l)
{
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
return wctob(__c);
}
@ -47,14 +44,14 @@ inline _LIBCPP_ALWAYS_INLINE
size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
size_t __len, mbstate_t *__ps, locale_t __l)
{
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
}
inline _LIBCPP_ALWAYS_INLINE
size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l)
{
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
return wcrtomb(__s, __wc, __ps);
}
@ -62,7 +59,7 @@ inline _LIBCPP_ALWAYS_INLINE
size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms,
size_t __len, mbstate_t *__ps, locale_t __l)
{
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
}
@ -70,28 +67,28 @@ inline _LIBCPP_ALWAYS_INLINE
size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
mbstate_t *__ps, locale_t __l)
{
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
return mbrtowc(__pwc, __s, __n, __ps);
}
inline _LIBCPP_ALWAYS_INLINE
int __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l)
{
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
return mbtowc(__pwc, __pmb, __max);
}
inline _LIBCPP_ALWAYS_INLINE
size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l)
{
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
return mbrlen(__s, __n, __ps);
}
inline _LIBCPP_ALWAYS_INLINE
lconv *__libcpp_localeconv_l(locale_t __l)
{
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
return localeconv();
}
@ -99,7 +96,7 @@ inline _LIBCPP_ALWAYS_INLINE
size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
mbstate_t *__ps, locale_t __l)
{
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
return mbsrtowcs(__dest, __src, __len, __ps);
}
@ -107,7 +104,7 @@ inline
int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
va_list __va;
va_start(__va, __format);
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
int __res = vsnprintf(__s, __n, __format, __va);
va_end(__va);
return __res;
@ -117,7 +114,7 @@ inline
int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
va_list __va;
va_start(__va, __format);
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
int __res = vasprintf(__s, __format, __va);
va_end(__va);
return __res;
@ -127,7 +124,7 @@ inline
int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
va_list __va;
va_start(__va, __format);
__locale_raii __current( uselocale(__l), uselocale );
__libcpp_locale_guard __current(__l);
int __res = vsscanf(__s, __format, __va);
va_end(__va);
return __res;

View File

@ -129,6 +129,12 @@
#define __has_keyword(__x) !(__is_identifier(__x))
#ifdef __has_include
#define __libcpp_has_include(__x) __has_include(__x)
#else
#define __libcpp_has_include(__x) 0
#endif
#if defined(__clang__)
#define _LIBCPP_COMPILER_CLANG
# ifndef __apple_build_version__
@ -968,7 +974,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
# if defined(__GNUC__) && ((__GNUC__ >= 5) || (__GNUC__ == 4 && \
(__GNUC_MINOR__ >= 3 || __GNUC_PATCHLEVEL__ >= 2))) && !defined(__GXX_RTTI)
# define _LIBCPP_NO_RTTI
# elif defined(_LIBCPP_MSVC) && !defined(_CPPRTTI)
# elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI)
# define _LIBCPP_NO_RTTI
# endif
#endif
@ -980,6 +986,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
// Thread API
#if !defined(_LIBCPP_HAS_NO_THREADS) && \
!defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
!defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
!defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
# if defined(__FreeBSD__) || \
defined(__Fuchsia__) || \
@ -987,7 +994,8 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
defined(__linux__) || \
defined(__APPLE__) || \
defined(__CloudABI__) || \
defined(__sun__)
defined(__sun__) || \
(defined(__MINGW32__) && __libcpp_has_include(<pthread.h>))
# define _LIBCPP_HAS_THREAD_API_PTHREAD
# elif defined(_LIBCPP_WIN32API)
# define _LIBCPP_HAS_THREAD_API_WIN32

View File

@ -49,6 +49,25 @@
_LIBCPP_BEGIN_NAMESPACE_STD
#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) || defined(_LIBCPP_MSVCRT)
struct __libcpp_locale_guard {
_LIBCPP_INLINE_VISIBILITY
__libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
_LIBCPP_INLINE_VISIBILITY
~__libcpp_locale_guard() {
if (__old_loc_)
uselocale(__old_loc_);
}
locale_t __old_loc_;
private:
__libcpp_locale_guard(__libcpp_locale_guard const&);
__libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
};
#endif
class _LIBCPP_TYPE_VIS locale;
template <class _Facet>

View File

@ -15,6 +15,7 @@
#include <chrono>
#include <system_error>
#include <__threading_support>
#include <__undef_min_max>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header

View File

@ -30,6 +30,7 @@
#include <Windows.h>
#include <process.h>
#include <fibersapi.h>
#include <__undef_min_max>
#endif
#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \

View File

@ -10,7 +10,7 @@
#ifdef min
#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
#if defined(_LIBCPP_MSVC)
#if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("macro min is incompatible with C++. Try #define NOMINMAX "
"before any Windows header. #undefing min")
#else
@ -22,7 +22,7 @@ _LIBCPP_WARNING("macro min is incompatible with C++. Try #define NOMINMAX "
#ifdef max
#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
#if defined(_LIBCPP_MSVC)
#if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("macro max is incompatible with C++. Try #define NOMINMAX "
"before any Windows header. #undefing max")
#else

View File

@ -644,8 +644,8 @@ template <class BidirectionalIterator, class Compare>
#if defined(__IBMCPP__)
#include "support/ibm/support.h"
#endif
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
#include "support/win32/support.h"
#if defined(_LIBCPP_COMPILER_MSVC)
#include <intrin.h>
#endif
#include <__undef_min_max>
@ -783,51 +783,132 @@ struct __debug_less
// Precondition: __x != 0
inline _LIBCPP_INLINE_VISIBILITY
unsigned
__ctz(unsigned __x)
{
unsigned __ctz(unsigned __x) {
#ifndef _LIBCPP_COMPILER_MSVC
return static_cast<unsigned>(__builtin_ctz(__x));
#else
static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
static_assert(sizeof(unsigned long) == 4, "");
unsigned long where;
// Search from LSB to MSB for first set bit.
// Returns zero if no set bit is found.
if (_BitScanForward(&where, mask))
return where;
return 32;
#endif
}
inline _LIBCPP_INLINE_VISIBILITY
unsigned long
__ctz(unsigned long __x)
{
unsigned long __ctz(unsigned long __x) {
#ifndef _LIBCPP_COMPILER_MSVC
return static_cast<unsigned long>(__builtin_ctzl(__x));
#else
static_assert(sizeof(unsigned long) == sizeof(unsigned), "");
return __ctz(static_cast<unsigned>(__x));
#endif
}
inline _LIBCPP_INLINE_VISIBILITY
unsigned long long
__ctz(unsigned long long __x)
{
unsigned long long __ctz(unsigned long long __x) {
#ifndef _LIBCPP_COMPILER_MSVC
return static_cast<unsigned long long>(__builtin_ctzll(__x));
#else
unsigned long where;
// Search from LSB to MSB for first set bit.
// Returns zero if no set bit is found.
#if defined(_LIBCPP_HAS_BITSCAN64)
(defined(_M_AMD64) || defined(__x86_64__))
if (_BitScanForward64(&where, mask))
return static_cast<int>(where);
#else
// Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
// Scan the Low Word.
if (_BitScanForward(&where, static_cast<unsigned long>(mask)))
return where;
// Scan the High Word.
if (_BitScanForward(&where, static_cast<unsigned long>(mask >> 32)))
return where + 32; // Create a bit offset from the LSB.
#endif
return 64;
#endif // _LIBCPP_COMPILER_MSVC
}
// Precondition: __x != 0
inline _LIBCPP_INLINE_VISIBILITY
unsigned
__clz(unsigned __x)
{
unsigned __clz(unsigned __x) {
#ifndef _LIBCPP_COMPILER_MSVC
return static_cast<unsigned>(__builtin_clz(__x));
#else
static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
static_assert(sizeof(unsigned long) == 4, "");
unsigned long where;
// Search from LSB to MSB for first set bit.
// Returns zero if no set bit is found.
if (_BitScanReverse(&where, mask))
return 31 - where;
return 32; // Undefined Behavior.
#endif
}
inline _LIBCPP_INLINE_VISIBILITY
unsigned long
__clz(unsigned long __x)
{
unsigned long __clz(unsigned long __x) {
#ifndef _LIBCPP_COMPILER_MSVC
return static_cast<unsigned long>(__builtin_clzl (__x));
#else
static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
return __clz(static_cast<unsigned>(__x));
#endif
}
inline _LIBCPP_INLINE_VISIBILITY
unsigned long long
__clz(unsigned long long __x)
{
unsigned long long __clz(unsigned long long __x) {
#ifndef _LIBCPP_COMPILER_MSVC
return static_cast<unsigned long long>(__builtin_clzll(__x));
#else
unsigned long where;
// BitScanReverse scans from MSB to LSB for first set bit.
// Returns 0 if no set bit is found.
#if defined(_LIBCPP_HAS_BITSCAN64)
if (_BitScanReverse64(&where, mask))
return static_cast<int>(63 - where);
#else
// Scan the high 32 bits.
if (_BitScanReverse(&where, static_cast<unsigned long>(mask >> 32)))
return 63 - (where + 32); // Create a bit offset from the MSB.
// Scan the low 32 bits.
if (_BitScanReverse(&where, static_cast<unsigned long>(mask)))
return 63 - where;
#endif
return 64; // Undefined Behavior.
#endif // _LIBCPP_COMPILER_MSVC
}
inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned __x) {return __builtin_popcount (__x);}
inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long __x) {return __builtin_popcountl (__x);}
inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long long __x) {return __builtin_popcountll(__x);}
inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned __x) {
#ifndef _LIBCPP_COMPILER_MSVC
return __builtin_popcount (__x);
#else
static_assert(sizeof(unsigned) == 4, "");
return __popcnt(__x);
#endif
}
inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long __x) {
#ifndef _LIBCPP_COMPILER_MSVC
return __builtin_popcountl (__x);
#else
static_assert(sizeof(unsigned long) == 4, "");
return __popcnt(__x);
#endif
}
inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long long __x) {
#ifndef _LIBCPP_COMPILER_MSVC
return __builtin_popcountll(__x);
#else
static_assert(sizeof(unsigned long long) == 8, "");
return __popcnt64(__x);
#endif
}
// all_of

View File

@ -40,15 +40,6 @@ int toupper(int c);
#ifdef __cplusplus
#if defined(_LIBCPP_MSVCRT)
// We support including .h headers inside 'extern "C"' contexts, so switch
// back to C++ linkage before including these C++ headers.
extern "C++" {
#include "support/win32/support.h"
#include "support/win32/locale_win32.h"
}
#endif // _LIBCPP_MSVCRT
#undef isalnum
#undef isalpha
#undef isblank

View File

@ -66,11 +66,11 @@ struct __abs<_Result, _Source, false> {
template<class _Tp>
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
_Tp __gcd(_Tp __m, _Tp __n)
_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN
inline _Tp __gcd(_Tp __m, _Tp __n)
{
static_assert((!is_signed<_Tp>::value), "" );
return __n == 0 ? __m : __gcd<_Tp>(__n, __m % __n);
return __n == 0 ? __m : _VSTD_LFTS_V2::__gcd<_Tp>(__n, __m % __n);
}
@ -84,8 +84,9 @@ gcd(_Tp __m, _Up __n)
static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" );
using _Rp = common_type_t<_Tp,_Up>;
using _Wp = make_unsigned_t<_Rp>;
return static_cast<_Rp>(__gcd(static_cast<_Wp>(__abs<_Rp, _Tp>()(__m)),
static_cast<_Wp>(__abs<_Rp, _Up>()(__n))));
return static_cast<_Rp>(_VSTD_LFTS_V2::__gcd(
static_cast<_Wp>(__abs<_Rp, _Tp>()(__m)),
static_cast<_Wp>(__abs<_Rp, _Up>()(__n))));
}
template<class _Tp, class _Up>
@ -100,7 +101,7 @@ lcm(_Tp __m, _Up __n)
return 0;
using _Rp = common_type_t<_Tp,_Up>;
_Rp __val1 = __abs<_Rp, _Tp>()(__m) / gcd(__m, __n);
_Rp __val1 = __abs<_Rp, _Tp>()(__m) / _VSTD_LFTS_V2::gcd(__m, __n);
_Rp __val2 = __abs<_Rp, _Up>()(__n);
_LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm");
return __val1 * __val2;

View File

@ -207,7 +207,7 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
#include <ext/__hash>
#if __DEPRECATED
#if defined(_LIBCPP_MSVC)
#if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>")
#else
# warning Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>

View File

@ -199,7 +199,7 @@ template <class Value, class Hash, class Pred, class Alloc>
#include <ext/__hash>
#if __DEPRECATED
#if defined(_LIBCPP_MSVC)
#if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>")
#else
# warning Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>

View File

@ -111,8 +111,8 @@ template<> class numeric_limits<cv long double>;
#include <__undef_min_max>
#if defined(_LIBCPP_MSVCRT)
#include "support/win32/limits_win32.h"
#if defined(_LIBCPP_COMPILER_MSVC)
#include "support/win32/limits_msvc_win32.h"
#endif // _LIBCPP_MSVCRT
#if defined(__IBMCPP__)

View File

@ -233,9 +233,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#define __cloc_defined
#endif
typedef _VSTD::remove_pointer<locale_t>::type __locale_struct;
typedef _VSTD::unique_ptr<__locale_struct, decltype(&freelocale)> __locale_unique_ptr;
// __scan_keyword
// Scans [__b, __e) until a match is found in the basic_strings range
// [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke).

View File

@ -996,11 +996,11 @@ struct __rebind_pointer {
// allocator_traits
namespace __has_pointer_type_imp
struct __has_pointer_type_imp
{
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::pointer* = 0);
}
};
template <class _Tp>
struct __has_pointer_type
@ -3924,7 +3924,10 @@ private:
template <class _Yp, class _OrigPtr>
_LIBCPP_INLINE_VISIBILITY
void
typename enable_if<is_convertible<_OrigPtr*,
const enable_shared_from_this<_Yp>*
>::value,
void>::type
__enable_weak_this(const enable_shared_from_this<_Yp>* __e,
_OrigPtr* __ptr) _NOEXCEPT
{
@ -3943,6 +3946,7 @@ private:
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
};
template<class _Tp>
inline
_LIBCPP_CONSTEXPR

View File

@ -222,11 +222,11 @@ struct __abs<_Result, _Source, false> {
template<class _Tp>
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN
_Tp __gcd(_Tp __m, _Tp __n)
{
static_assert((!is_signed<_Tp>::value), "");
return __n == 0 ? __m : __gcd<_Tp>(__n, __m % __n);
return __n == 0 ? __m : _VSTD::__gcd<_Tp>(__n, __m % __n);
}
@ -240,8 +240,9 @@ gcd(_Tp __m, _Up __n)
static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" );
using _Rp = common_type_t<_Tp,_Up>;
using _Wp = make_unsigned_t<_Rp>;
return static_cast<_Rp>(__gcd(static_cast<_Wp>(__abs<_Rp, _Tp>()(__m)),
static_cast<_Wp>(__abs<_Rp, _Up>()(__n))));
return static_cast<_Rp>(_VSTD::__gcd(
static_cast<_Wp>(__abs<_Rp, _Tp>()(__m)),
static_cast<_Wp>(__abs<_Rp, _Up>()(__n))));
}
template<class _Tp, class _Up>
@ -256,7 +257,7 @@ lcm(_Tp __m, _Up __n)
return 0;
using _Rp = common_type_t<_Tp,_Up>;
_Rp __val1 = __abs<_Rp, _Tp>()(__m) / gcd(__m, __n);
_Rp __val1 = __abs<_Rp, _Tp>()(__m) / _VSTD::gcd(__m, __n);
_Rp __val2 = __abs<_Rp, _Up>()(__n);
_LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm");
return __val1 * __val2;

View File

@ -111,8 +111,9 @@ void perror(const char* s);
// snprintf
#if defined(_LIBCPP_MSVCRT)
extern "C++" {
#include "support/win32/support.h"
extern "C" {
int vasprintf(char **sptr, const char *__restrict fmt, va_list ap);
int asprintf(char **sptr, const char *__restrict fmt, ...);
}
#endif

View File

@ -97,10 +97,6 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
extern "C++" {
#ifdef _LIBCPP_MSVCRT
#include "support/win32/locale_win32.h"
#endif // _LIBCPP_MSVCRT
#undef abs
#undef div
#undef labs

View File

@ -103,7 +103,6 @@ namespace std {
constexpr const_pointer data() const noexcept;
// 7.7, basic_string_view modifiers
constexpr void clear() noexcept;
constexpr void remove_prefix(size_type n);
constexpr void remove_suffix(size_type n);
constexpr void swap(basic_string_view& s) noexcept;
@ -292,13 +291,6 @@ public:
const_pointer data() const _NOEXCEPT { return __data; }
// [string.view.modifiers], modifiers:
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT
{
__data = nullptr;
__size = 0;
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
void remove_prefix(size_type __n) _NOEXCEPT
{

View File

@ -1,5 +1,5 @@
// -*- C++ -*-
//===--------------------- support/win32/limits_win32.h -------------------===//
//===------------------ support/win32/limits_msvc_win32.h -----------------===//
//
// The LLVM Compiler Infrastructure
//
@ -8,17 +8,21 @@
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H
#define _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H
#ifndef _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H
#define _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H
#if !defined(_LIBCPP_MSVCRT)
#error "This header complements the Microsoft C Runtime library, and should not be included otherwise."
#else
#endif
#if defined(__clang__)
#error "This header should only be included when using Microsofts C1XX frontend"
#endif
#include <limits.h> // CHAR_BIT
#include <float.h> // limit constants
#include <math.h> // HUGE_VAL
#include <ymath.h> // internal MSVC header providing the needed functionality
#if ! defined(__clang__)
#define __CHAR_BIT__ CHAR_BIT
#define __FLT_MANT_DIG__ FLT_MANT_DIG
@ -61,19 +65,8 @@
#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
// __builtin replacements/workarounds
#include <math.h> // HUGE_VAL
#include <ymath.h> // internal MSVC header providing the needed functionality
#define __builtin_huge_val() HUGE_VAL
#define __builtin_huge_valf() _FInf._Float
#define __builtin_huge_vall() _LInf._Long_double
#define __builtin_nan(__dummy) _Nan._Double
#define __builtin_nanf(__dummy) _FNan._Float
#define __builtin_nanl(__dummmy) _LNan._Long_double
#define __builtin_nans(__dummy) _Snan._Double
#define __builtin_nansf(__dummy) _FSnan._Float
#define __builtin_nansl(__dummy) _LSnan._Long_double
#endif // ! defined(__clang__)
#endif // _LIBCPP_MSVCRT
#endif // _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H
#endif // _LIBCPP_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H

View File

@ -1,33 +0,0 @@
// -*- C++ -*-
//===----------------- support/win32/locale_mgmt_win32.h ------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_MGMT_WIN32_H
#define _LIBCPP_SUPPORT_WIN32_LOCALE_MGMT_WIN32_H
#include <xlocinfo.h> // _locale_t
#define locale_t _locale_t
#define LC_COLLATE_MASK _M_COLLATE
#define LC_CTYPE_MASK _M_CTYPE
#define LC_MONETARY_MASK _M_MONETARY
#define LC_NUMERIC_MASK _M_NUMERIC
#define LC_TIME_MASK _M_TIME
#define LC_MESSAGES_MASK _M_MESSAGES
#define LC_ALL_MASK ( LC_COLLATE_MASK \
| LC_CTYPE_MASK \
| LC_MESSAGES_MASK \
| LC_MONETARY_MASK \
| LC_NUMERIC_MASK \
| LC_TIME_MASK )
#define freelocale _free_locale
// FIXME: base currently unused. Needs manual work to construct the new locale
locale_t newlocale( int mask, const char * locale, locale_t base );
locale_t uselocale( locale_t newloc );
#endif // _LIBCPP_SUPPORT_WIN32_LOCALE_MGMT_WIN32_H

View File

@ -12,9 +12,30 @@
#define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
#include <__config>
#include "support/win32/support.h"
#include "support/win32/locale_mgmt_win32.h"
#include <stdio.h>
#include <xlocinfo.h> // _locale_t
#define LC_COLLATE_MASK _M_COLLATE
#define LC_CTYPE_MASK _M_CTYPE
#define LC_MONETARY_MASK _M_MONETARY
#define LC_NUMERIC_MASK _M_NUMERIC
#define LC_TIME_MASK _M_TIME
#define LC_MESSAGES_MASK _M_MESSAGES
#define LC_ALL_MASK ( LC_COLLATE_MASK \
| LC_CTYPE_MASK \
| LC_MESSAGES_MASK \
| LC_MONETARY_MASK \
| LC_NUMERIC_MASK \
| LC_TIME_MASK )
#define locale_t _locale_t
// Locale management functions
#define freelocale _free_locale
// FIXME: base currently unused. Needs manual work to construct the new locale
locale_t newlocale( int mask, const char * locale, locale_t base );
locale_t uselocale( locale_t newloc );
lconv *localeconv_l( locale_t loc );
size_t mbrlen_l( const char *__restrict s, size_t n,
@ -88,7 +109,6 @@ _LIBCPP_FUNC_VIS int snprintf_l(char *ret, size_t n, locale_t loc, const char *f
_LIBCPP_FUNC_VIS int asprintf_l( char **ret, locale_t loc, const char *format, ... );
_LIBCPP_FUNC_VIS int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap );
// not-so-pressing FIXME: use locale to determine blank characters
inline int isblank_l( int c, locale_t /*loc*/ )
{
@ -99,10 +119,4 @@ inline int iswblank_l( wint_t c, locale_t /*loc*/ )
return ( c == L' ' || c == L'\t' );
}
#if defined(_LIBCPP_MSVCRT)
inline int isblank( int c, locale_t /*loc*/ )
{ return ( c == ' ' || c == '\t' ); }
inline int iswblank( wint_t c, locale_t /*loc*/ )
{ return ( c == L' ' || c == L'\t' ); }
#endif // _LIBCPP_MSVCRT
#endif // _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H

View File

@ -1,177 +0,0 @@
// -*- C++ -*-
//===----------------------- support/win32/support.h ----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_SUPPORT_WIN32_SUPPORT_H
#define _LIBCPP_SUPPORT_WIN32_SUPPORT_H
// Functions and constants used in libc++ that
// are missing from the Windows C library.
#include <wchar.h> // mbstate_t
#include <cstdarg> // va_ macros
// "builtins" not implemented here for Clang or GCC as they provide
// implementations. Assuming required for elsewhere else, certainly MSVC.
#if defined(_LIBCPP_COMPILER_MSVC)
#include <intrin.h>
#endif
#define swprintf _snwprintf
#define vswprintf _vsnwprintf
#ifndef NOMINMAX
#define NOMINMAX
#endif
// The mingw headers already define these as static.
#ifndef __MINGW32__
extern "C" {
int vasprintf(char **sptr, const char *__restrict fmt, va_list ap);
int asprintf(char **sptr, const char *__restrict fmt, ...);
size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
size_t nmc, size_t len, mbstate_t *__restrict ps);
size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
size_t nwc, size_t len, mbstate_t *__restrict ps);
}
#endif // __MINGW32__
#if defined(_LIBCPP_COMPILER_MSVC)
// Bit builtin's make these assumptions when calling _BitScanForward/Reverse
// etc. These assumptions are expected to be true for Win32/Win64 which this
// file supports.
static_assert(sizeof(unsigned long long) == 8, "");
static_assert(sizeof(unsigned long) == 4, "");
static_assert(sizeof(unsigned int) == 4, "");
_LIBCPP_ALWAYS_INLINE int __builtin_popcount(unsigned int x)
{
// Binary: 0101...
static const unsigned int m1 = 0x55555555;
// Binary: 00110011..
static const unsigned int m2 = 0x33333333;
// Binary: 4 zeros, 4 ones ...
static const unsigned int m4 = 0x0f0f0f0f;
// The sum of 256 to the power of 0,1,2,3...
static const unsigned int h01 = 0x01010101;
// Put count of each 2 bits into those 2 bits.
x -= (x >> 1) & m1;
// Put count of each 4 bits into those 4 bits.
x = (x & m2) + ((x >> 2) & m2);
// Put count of each 8 bits into those 8 bits.
x = (x + (x >> 4)) & m4;
// Returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24).
return (x * h01) >> 24;
}
_LIBCPP_ALWAYS_INLINE int __builtin_popcountl(unsigned long x)
{
return __builtin_popcount(static_cast<int>(x));
}
_LIBCPP_ALWAYS_INLINE int __builtin_popcountll(unsigned long long x)
{
// Binary: 0101...
static const unsigned long long m1 = 0x5555555555555555;
// Binary: 00110011..
static const unsigned long long m2 = 0x3333333333333333;
// Binary: 4 zeros, 4 ones ...
static const unsigned long long m4 = 0x0f0f0f0f0f0f0f0f;
// The sum of 256 to the power of 0,1,2,3...
static const unsigned long long h01 = 0x0101010101010101;
// Put count of each 2 bits into those 2 bits.
x -= (x >> 1) & m1;
// Put count of each 4 bits into those 4 bits.
x = (x & m2) + ((x >> 2) & m2);
// Put count of each 8 bits into those 8 bits.
x = (x + (x >> 4)) & m4;
// Returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ...
return static_cast<int>((x * h01) >> 56);
}
// Returns the number of trailing 0-bits in x, starting at the least significant
// bit position. If x is 0, the result is undefined.
_LIBCPP_ALWAYS_INLINE int __builtin_ctzll(unsigned long long mask)
{
unsigned long where;
// Search from LSB to MSB for first set bit.
// Returns zero if no set bit is found.
#if defined(_LIBCPP_HAS_BITSCAN64)
(defined(_M_AMD64) || defined(__x86_64__))
if (_BitScanForward64(&where, mask))
return static_cast<int>(where);
#else
// Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
// Scan the Low Word.
if (_BitScanForward(&where, static_cast<unsigned long>(mask)))
return static_cast<int>(where);
// Scan the High Word.
if (_BitScanForward(&where, static_cast<unsigned long>(mask >> 32)))
return static_cast<int>(where + 32); // Create a bit offset from the LSB.
#endif
return 64;
}
_LIBCPP_ALWAYS_INLINE int __builtin_ctzl(unsigned long mask)
{
unsigned long where;
// Search from LSB to MSB for first set bit.
// Returns zero if no set bit is found.
if (_BitScanForward(&where, mask))
return static_cast<int>(where);
return 32;
}
_LIBCPP_ALWAYS_INLINE int __builtin_ctz(unsigned int mask)
{
// Win32 and Win64 expectations.
static_assert(sizeof(mask) == 4, "");
static_assert(sizeof(unsigned long) == 4, "");
return __builtin_ctzl(static_cast<unsigned long>(mask));
}
// Returns the number of leading 0-bits in x, starting at the most significant
// bit position. If x is 0, the result is undefined.
_LIBCPP_ALWAYS_INLINE int __builtin_clzll(unsigned long long mask)
{
unsigned long where;
// BitScanReverse scans from MSB to LSB for first set bit.
// Returns 0 if no set bit is found.
#if defined(_LIBCPP_HAS_BITSCAN64)
if (_BitScanReverse64(&where, mask))
return static_cast<int>(63 - where);
#else
// Scan the high 32 bits.
if (_BitScanReverse(&where, static_cast<unsigned long>(mask >> 32)))
return static_cast<int>(63 -
(where + 32)); // Create a bit offset from the MSB.
// Scan the low 32 bits.
if (_BitScanReverse(&where, static_cast<unsigned long>(mask)))
return static_cast<int>(63 - where);
#endif
return 64; // Undefined Behavior.
}
_LIBCPP_ALWAYS_INLINE int __builtin_clzl(unsigned long mask)
{
unsigned long where;
// Search from LSB to MSB for first set bit.
// Returns zero if no set bit is found.
if (_BitScanReverse(&where, mask))
return static_cast<int>(31 - where);
return 32; // Undefined Behavior.
}
_LIBCPP_ALWAYS_INLINE int __builtin_clz(unsigned int x)
{
return __builtin_clzl(x);
}
#endif // _LIBCPP_MSVC
#endif // _LIBCPP_SUPPORT_WIN32_SUPPORT_H

View File

@ -425,30 +425,21 @@ struct __base {
constexpr auto __fmatrix =
__make_fmatrix<_Visitor&&,
decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>();
const size_t __indices[] = {__vs.index()...};
return __at(__fmatrix, __indices)(_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Vs>(__vs).__as_base()...);
return __at(__fmatrix, __vs.index()...)(
_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Vs>(__vs).__as_base()...);
}
private:
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr const _Tp& __at_impl(const _Tp& __elem, const size_t*) {
return __elem;
}
static constexpr const _Tp& __at(const _Tp& __elem) { return __elem; }
template <class _Tp, size_t _Np>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto&& __at_impl(const array<_Tp, _Np>& __elems,
const size_t* __index) {
return __at_impl(__elems[*__index], __index + 1);
}
template <class _Tp, size_t _Np, size_t _Ip>
template <class _Tp, size_t _Np, typename... _Indices>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto&& __at(const array<_Tp, _Np>& __elems,
const size_t (&__indices)[_Ip]) {
return __at_impl(__elems, begin(__indices));
size_t __index, _Indices... __indices) {
return __at(__elems[__index], __indices...);
}
template <class _Fp, class... _Fs>
@ -1140,7 +1131,7 @@ public:
: __impl(in_place_index<_Ip>, _VSTD::forward<_Arg>(__arg)) {}
template <size_t _Ip, class... _Args,
enable_if_t<(_Ip < sizeof...(_Types)), int> = 0,
class = enable_if_t<(_Ip < sizeof...(_Types)), int>,
class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
inline _LIBCPP_INLINE_VISIBILITY

View File

@ -166,9 +166,12 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
}
#endif
#if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT) || defined(__MINGW32__))
extern "C++" {
#include <support/win32/support.h> // pull in *swprintf defines
#if defined(__cplusplus) && defined(_LIBCPP_MSVCRT)
extern "C" {
size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
size_t nmc, size_t len, mbstate_t *__restrict ps);
size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
size_t nwc, size_t len, mbstate_t *__restrict ps);
} // extern "C++"
#endif // __cplusplus && _LIBCPP_MSVCRT

View File

@ -29,7 +29,7 @@
#endif
#if !defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS)
# if defined(_LIBCPP_MSVC)
# if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("Building libc++ without __atomic builtins is unsupported")
# else
# warning Building libc++ without __atomic builtins is unsupported

View File

@ -45,6 +45,24 @@
_LIBCPP_BEGIN_NAMESPACE_STD
struct __libcpp_unique_locale {
__libcpp_unique_locale(const char* nm) : __loc_(newlocale(LC_ALL_MASK, nm, 0)) {}
~__libcpp_unique_locale() {
if (__loc_)
freelocale(__loc_);
}
explicit operator bool() const { return __loc_; }
locale_t& get() { return __loc_; }
locale_t __loc_;
private:
__libcpp_unique_locale(__libcpp_unique_locale const&);
__libcpp_unique_locale& operator=(__libcpp_unique_locale const&);
};
#ifdef __cloc_defined
locale_t __cloc() {
// In theory this could create a race condition. In practice
@ -4185,7 +4203,7 @@ __widen_from_utf8<32>::~__widen_from_utf8()
static bool checked_string_to_wchar_convert(wchar_t& dest,
const char* ptr,
__locale_struct* loc) {
locale_t loc) {
if (*ptr == '\0')
return false;
mbstate_t mb = {};
@ -4200,7 +4218,7 @@ static bool checked_string_to_wchar_convert(wchar_t& dest,
static bool checked_string_to_char_convert(char& dest,
const char* ptr,
__locale_struct* __loc) {
locale_t __loc) {
if (*ptr == '\0')
return false;
if (!ptr[1]) {
@ -4295,8 +4313,8 @@ numpunct_byname<char>::__init(const char* nm)
{
if (strcmp(nm, "C") != 0)
{
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
if (loc == nullptr)
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("numpunct_byname<char>::numpunct_byname"
" failed to construct for " + string(nm));
@ -4333,8 +4351,8 @@ numpunct_byname<wchar_t>::__init(const char* nm)
{
if (strcmp(nm, "C") != 0)
{
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
if (loc == nullptr)
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("numpunct_byname<wchar_t>::numpunct_byname"
" failed to construct for " + string(nm));
@ -5820,8 +5838,8 @@ void
moneypunct_byname<char, false>::init(const char* nm)
{
typedef moneypunct<char, false> base;
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
if (loc == nullptr)
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));
@ -5864,8 +5882,8 @@ void
moneypunct_byname<char, true>::init(const char* nm)
{
typedef moneypunct<char, true> base;
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
if (loc == nullptr)
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));
@ -5924,8 +5942,8 @@ void
moneypunct_byname<wchar_t, false>::init(const char* nm)
{
typedef moneypunct<wchar_t, false> base;
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
if (loc == nullptr)
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));
lconv* lc = __libcpp_localeconv_l(loc.get());
@ -5989,8 +6007,8 @@ void
moneypunct_byname<wchar_t, true>::init(const char* nm)
{
typedef moneypunct<wchar_t, true> base;
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
if (loc == nullptr)
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));

View File

@ -13,9 +13,6 @@
#include "cerrno"
#include "limits"
#include "stdexcept"
#ifdef _LIBCPP_MSVCRT
#include "support/win32/support.h"
#endif // _LIBCPP_MSVCRT
#include <stdio.h>
_LIBCPP_BEGIN_NAMESPACE_STD
@ -430,7 +427,7 @@ get_swprintf()
#ifndef _LIBCPP_MSVCRT
return swprintf;
#else
return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(swprintf);
return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(_snwprintf);
#endif
}

View File

@ -10,6 +10,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <yvals.h> // for _CRTIMP2_PURE
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(_Out_ void*);
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(_Inout_ void*);

View File

@ -13,14 +13,14 @@
#include <memory>
#include <type_traits>
typedef _VSTD::remove_pointer<locale_t>::type __locale_struct;
typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
using std::__libcpp_locale_guard;
// FIXME: base currently unused. Needs manual work to construct the new locale
locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
{
return _create_locale( mask, locale );
}
locale_t uselocale( locale_t newloc )
{
locale_t old_locale = _get_current_locale();
@ -36,59 +36,59 @@ locale_t uselocale( locale_t newloc )
}
lconv *localeconv_l( locale_t loc )
{
__locale_raii __current( uselocale(loc), uselocale );
__libcpp_locale_guard __current(loc);
return localeconv();
}
size_t mbrlen_l( const char *__restrict s, size_t n,
mbstate_t *__restrict ps, locale_t loc )
{
__locale_raii __current( uselocale(loc), uselocale );
__libcpp_locale_guard __current(loc);
return mbrlen( s, n, ps );
}
size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
size_t len, mbstate_t *__restrict ps, locale_t loc )
{
__locale_raii __current( uselocale(loc), uselocale );
__libcpp_locale_guard __current(loc);
return mbsrtowcs( dst, src, len, ps );
}
size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps,
locale_t loc )
{
__locale_raii __current( uselocale(loc), uselocale );
__libcpp_locale_guard __current(loc);
return wcrtomb( s, wc, ps );
}
size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s,
size_t n, mbstate_t *__restrict ps, locale_t loc )
{
__locale_raii __current( uselocale(loc), uselocale );
__libcpp_locale_guard __current(loc);
return mbrtowc( pwc, s, n, ps );
}
size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc )
{
__locale_raii __current( uselocale(loc), uselocale );
__libcpp_locale_guard __current(loc);
return mbsnrtowcs( dst, src, nms, len, ps );
}
size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src,
size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc )
{
__locale_raii __current( uselocale(loc), uselocale );
__libcpp_locale_guard __current(loc);
return wcsnrtombs( dst, src, nwc, len, ps );
}
wint_t btowc_l( int c, locale_t loc )
{
__locale_raii __current( uselocale(loc), uselocale );
__libcpp_locale_guard __current(loc);
return btowc( c );
}
int wctob_l( wint_t c, locale_t loc )
{
__locale_raii __current( uselocale(loc), uselocale );
__libcpp_locale_guard __current(loc);
return wctob( c );
}
int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...)
{
__locale_raii __current( uselocale(loc), uselocale );
__libcpp_locale_guard __current(loc);
va_list ap;
va_start( ap, format );
int result = vsnprintf( ret, n, format, ap );
@ -106,6 +106,6 @@ int asprintf_l( char **ret, locale_t loc, const char *format, ... )
}
int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap )
{
__locale_raii __current( uselocale(loc), uselocale );
__libcpp_locale_guard __current(loc);
return vasprintf( ret, format, ap );
}

View File

@ -99,7 +99,7 @@ thread::hardware_concurrency() _NOEXCEPT
#else // defined(CTL_HW) && defined(HW_NCPU)
// TODO: grovel through /proc or check cpuid on x86 and similar
// instructions on other architectures.
# if defined(_LIBCPP_MSVC)
# if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("hardware_concurrency not yet implemented")
# else
# warning hardware_concurrency not yet implemented

View File

@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
// REQUIRES: libcpp-has-no-global-filesystem-namespace
#include <cstdio>
int main() {

View File

@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
// REQUIRES: libcpp-has-no-global-filesystem-namespace
#include <cstdio>
int main() {

View File

@ -35,7 +35,6 @@
void sig_action(int) {}
#include <iostream>
int main()
{
int ec;

View File

@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// test that <bitset> includes <cstddef>, <string>, <stdexcept> and <iosfwd>
#include <bitset>
#ifndef _LIBCPP_CSTDDEF
#error <cstddef> has not been included
#endif
#ifndef _LIBCPP_STRING
#error <string> has not been included
#endif
#ifndef _LIBCPP_STDEXCEPT
#error <stdexcept> has not been included
#endif
#ifndef _LIBCPP_IOSFWD
#error <iosfwd> has not been included
#endif
int main()
{
}

View File

@ -8,6 +8,12 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
// GCC returns true for __is_trivially_constructible(void, int)
// See gcc.gnu.org/PR80682
// NOTE: This has been fixed in trunk and will be backported soon.
// XFAIL: gcc-7, gcc-6, gcc-5, gcc-4
// <experimental/type_traits>
#include <experimental/type_traits>

View File

@ -1,2 +0,0 @@
if 'libcpp-has-no-global-filesystem-namespace' not in config.available_features:
config.unsupported = True

View File

@ -15,7 +15,7 @@
// XFAIL: clang-3, apple-clang-7, apple-clang-8
// None of the current GCC compilers support this.
// XFAIL: gcc
// XFAIL: gcc-5, gcc-6
// XFAIL: with_system_cxx_lib=macosx10.12
// XFAIL: with_system_cxx_lib=macosx10.11

View File

@ -13,7 +13,7 @@
// UNSUPPORTED: sanitizer-new-delete
// FIXME change this to XFAIL.
// UNSUPPORTED: no-aligned-allocation
// UNSUPPORTED: no-aligned-allocation && !gcc
// XFAIL: with_system_cxx_lib=macosx10.12
// XFAIL: with_system_cxx_lib=macosx10.11

View File

@ -13,7 +13,7 @@
// UNSUPPORTED: sanitizer-new-delete
// FIXME turn this into an XFAIL
// UNSUPPORTED: no-aligned-allocation
// UNSUPPORTED: no-aligned-allocation && !gcc
// XFAIL: with_system_cxx_lib=macosx10.12
// XFAIL: with_system_cxx_lib=macosx10.11

View File

@ -17,7 +17,7 @@
// XFAIL: with_system_cxx_lib=macosx10.7
// XFAIL: with_system_cxx_lib=macosx10.8
// XFAIL: no-aligned-allocation
// XFAIL: no-aligned-allocation && !gcc
// On Windows libc++ doesn't provide its own definitions for new/delete
// but instead depends on the ones in VCRuntime. However VCRuntime does not

View File

@ -10,7 +10,8 @@
// UNSUPPORTED: c++98, c++03, c++11, c++14
// UNSUPPORTED: sanitizer-new-delete
// XFAIL: no-aligned-allocation
// NOTE: GCC doesn't provide the -faligned-allocation flag to test for
// XFAIL: no-aligned-allocation && !gcc
// test operator new replacement

View File

@ -14,7 +14,7 @@
// XFAIL: clang-3, apple-clang-7, apple-clang-8
// None of the current GCC compilers support this.
// XFAIL: gcc
// XFAIL: gcc-5, gcc-6
// XFAIL: with_system_cxx_lib=macosx10.12
// XFAIL: with_system_cxx_lib=macosx10.11

View File

@ -20,7 +20,7 @@
// UNSUPPORTED: sanitizer-new-delete
// FIXME turn this into an XFAIL
// UNSUPPORTED: no-aligned-allocation
// UNSUPPORTED: no-aligned-allocation && !gcc
// On Windows libc++ doesn't provide its own definitions for new/delete
// but instead depends on the ones in VCRuntime. However VCRuntime does not

View File

@ -20,7 +20,7 @@
// UNSUPPORTED: sanitizer-new-delete
// FIXME turn this into an XFAIL
// UNSUPPORTED: no-aligned-allocation
// UNSUPPORTED: no-aligned-allocation && !gcc
// On Windows libc++ doesn't provide its own definitions for new/delete
// but instead depends on the ones in VCRuntime. However VCRuntime does not

View File

@ -17,7 +17,8 @@
// XFAIL: with_system_cxx_lib=macosx10.7
// XFAIL: with_system_cxx_lib=macosx10.8
// XFAIL: no-aligned-allocation
// NOTE: gcc doesn't provide -faligned-allocation flag to test for
// XFAIL: no-aligned-allocation && !gcc
// On Windows libc++ doesn't provide its own definitions for new/delete
// but instead depends on the ones in VCRuntime. However VCRuntime does not

View File

@ -10,7 +10,8 @@
// UNSUPPORTED: c++98, c++03, c++11, c++14
// UNSUPPORTED: sanitizer-new-delete
// XFAIL: no-aligned-allocation
// NOTE: GCC doesn't provide a -faligned-allocation flag
// XFAIL: no-aligned-allocation && !gcc
// test operator new replacement

View File

@ -11,9 +11,6 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// constexpr byte& operator &=(byte l, byte r) noexcept;
@ -26,9 +23,9 @@ constexpr std::byte test(std::byte b1, std::byte b2) {
int main () {
std::byte b; // not constexpr, just used in noexcept check
constexpr std::byte b1{1};
constexpr std::byte b8{8};
constexpr std::byte b9{9};
constexpr std::byte b1{static_cast<std::byte>(1)};
constexpr std::byte b8{static_cast<std::byte>(8)};
constexpr std::byte b9{static_cast<std::byte>(9)};
static_assert(noexcept(b &= b), "" );

View File

@ -11,16 +11,13 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// constexpr byte operator&(byte l, byte r) noexcept;
int main () {
constexpr std::byte b1{1};
constexpr std::byte b8{8};
constexpr std::byte b9{9};
constexpr std::byte b1{static_cast<std::byte>(1)};
constexpr std::byte b8{static_cast<std::byte>(8)};
constexpr std::byte b9{static_cast<std::byte>(9)};
static_assert(noexcept(b1 & b8), "" );

View File

@ -0,0 +1,21 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <cstddef>
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8.0
int main () {
constexpr std::byte b{42};
static_assert(std::to_integer<int>(b) == 42, "");
}

View File

@ -11,9 +11,6 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// template <class IntegerType>
// constexpr byte& operator<<=(byte& b, IntegerType shift) noexcept;
@ -28,8 +25,8 @@ constexpr std::byte test(std::byte b) {
int main () {
std::byte b; // not constexpr, just used in noexcept check
constexpr std::byte b2{2};
constexpr std::byte b3{3};
constexpr std::byte b2{static_cast<std::byte>(2)};
constexpr std::byte b3{static_cast<std::byte>(3)};
static_assert(noexcept(b <<= 2), "" );

View File

@ -11,9 +11,6 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// template <class IntegerType>
// constexpr byte operator <<(byte b, IntegerType shift) noexcept;
@ -21,6 +18,6 @@
// is_integral_v<IntegerType> is true.
int main () {
constexpr std::byte b1{1};
constexpr std::byte b1{static_cast<std::byte>(1)};
constexpr std::byte b2 = b1 << 2.0f;
}

View File

@ -11,9 +11,6 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// template <class IntegerType>
// constexpr byte operator <<(byte b, IntegerType shift) noexcept;
@ -21,8 +18,8 @@
// is_integral_v<IntegerType> is true.
int main () {
constexpr std::byte b1{1};
constexpr std::byte b3{3};
constexpr std::byte b1{static_cast<std::byte>(1)};
constexpr std::byte b3{static_cast<std::byte>(3)};
static_assert(noexcept(b3 << 2), "" );

View File

@ -11,16 +11,13 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// constexpr byte operator~(byte b) noexcept;
int main () {
constexpr std::byte b1{1};
constexpr std::byte b2{2};
constexpr std::byte b8{8};
constexpr std::byte b1{static_cast<std::byte>(1)};
constexpr std::byte b2{static_cast<std::byte>(2)};
constexpr std::byte b8{static_cast<std::byte>(8)};
static_assert(noexcept(~b1), "" );

View File

@ -11,9 +11,6 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// constexpr byte& operator |=(byte l, byte r) noexcept;
@ -26,9 +23,9 @@ constexpr std::byte test(std::byte b1, std::byte b2) {
int main () {
std::byte b; // not constexpr, just used in noexcept check
constexpr std::byte b1{1};
constexpr std::byte b2{2};
constexpr std::byte b8{8};
constexpr std::byte b1{static_cast<std::byte>(1)};
constexpr std::byte b2{static_cast<std::byte>(2)};
constexpr std::byte b8{static_cast<std::byte>(8)};
static_assert(noexcept(b |= b), "" );

View File

@ -11,16 +11,13 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// constexpr byte operator|(byte l, byte r) noexcept;
int main () {
constexpr std::byte b1{1};
constexpr std::byte b2{2};
constexpr std::byte b8{8};
constexpr std::byte b1{static_cast<std::byte>(1)};
constexpr std::byte b2{static_cast<std::byte>(2)};
constexpr std::byte b8{static_cast<std::byte>(8)};
static_assert(noexcept(b1 | b2), "" );

View File

@ -11,9 +11,6 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// template <class IntegerType>
// constexpr byte& operator>>=(byte& b, IntegerType shift) noexcept;
@ -28,8 +25,8 @@ constexpr std::byte test(std::byte b) {
int main () {
std::byte b; // not constexpr, just used in noexcept check
constexpr std::byte b16{16};
constexpr std::byte b192{192};
constexpr std::byte b16{static_cast<std::byte>(16)};
constexpr std::byte b192{static_cast<std::byte>(192)};
static_assert(noexcept(b >>= 2), "" );

View File

@ -11,9 +11,6 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// template <class IntegerType>
// constexpr byte operator >>(byte b, IntegerType shift) noexcept;
@ -21,6 +18,6 @@
// is_integral_v<IntegerType> is true.
int main () {
constexpr std::byte b1{1};
constexpr std::byte b1{static_cast<std::byte>(1)};
constexpr std::byte b2 = b1 >> 2.0f;
}

View File

@ -11,9 +11,6 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// template <class IntegerType>
// constexpr byte operator <<(byte b, IntegerType shift) noexcept;
@ -27,8 +24,8 @@ constexpr std::byte test(std::byte b) {
int main () {
constexpr std::byte b100{100};
constexpr std::byte b115{115};
constexpr std::byte b100{static_cast<std::byte>(100)};
constexpr std::byte b115{static_cast<std::byte>(115)};
static_assert(noexcept(b100 << 2), "" );

View File

@ -11,9 +11,6 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// template <class IntegerType>
// constexpr IntegerType to_integer(byte b) noexcept;
@ -21,6 +18,6 @@
// is_integral_v<IntegerType> is true.
int main () {
constexpr std::byte b1{1};
constexpr std::byte b1{static_cast<std::byte>(1)};
auto f = std::to_integer<float>(b1);
}

View File

@ -11,9 +11,6 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// template <class IntegerType>
// constexpr IntegerType to_integer(byte b) noexcept;
@ -21,8 +18,8 @@
// is_integral_v<IntegerType> is true.
int main () {
constexpr std::byte b1{1};
constexpr std::byte b3{3};
constexpr std::byte b1{static_cast<std::byte>(1)};
constexpr std::byte b3{static_cast<std::byte>(3)};
static_assert(noexcept(std::to_integer<int>(b1)), "" );
static_assert(std::is_same<int, decltype(std::to_integer<int>(b1))>::value, "" );

View File

@ -11,9 +11,6 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// constexpr byte& operator ^=(byte l, byte r) noexcept;
@ -26,9 +23,9 @@ constexpr std::byte test(std::byte b1, std::byte b2) {
int main () {
std::byte b; // not constexpr, just used in noexcept check
constexpr std::byte b1{1};
constexpr std::byte b8{8};
constexpr std::byte b9{9};
constexpr std::byte b1{static_cast<std::byte>(1)};
constexpr std::byte b8{static_cast<std::byte>(8)};
constexpr std::byte b9{static_cast<std::byte>(9)};
static_assert(noexcept(b ^= b), "" );

View File

@ -11,16 +11,13 @@
#include <test_macros.h>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// The following compilers don't like "std::byte b1{1}"
// UNSUPPORTED: clang-3.5, clang-3.6, clang-3.7, clang-3.8
// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8.0
// constexpr byte operator^(byte l, byte r) noexcept;
int main () {
constexpr std::byte b1{1};
constexpr std::byte b8{8};
constexpr std::byte b9{9};
constexpr std::byte b1{static_cast<std::byte>(1)};
constexpr std::byte b8{static_cast<std::byte>(8)};
constexpr std::byte b9{static_cast<std::byte>(9)};
static_assert(noexcept(b1 ^ b8), "" );

View File

@ -25,307 +25,329 @@
#include <codecvt>
#include <cassert>
int main()
{
{
typedef std::codecvt_utf16<wchar_t> C;
C c;
wchar_t w = 0x40003;
char n[4] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[0] == char(0xD8));
assert(n[1] == char(0xC0));
assert(n[2] == char(0xDC));
assert(n[3] == char(0x03));
template <class CharT, size_t = sizeof(CharT)>
struct TestHelper;
template <class CharT>
struct TestHelper<CharT, 2> {
static void test();
};
template <class CharT>
struct TestHelper<CharT, 4> {
static void test();
};
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[0] == char(0x10));
assert(n[1] == char(0x05));
assert(n[2] == char(0xDC));
assert(n[3] == char(0x03));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[0] == char(0x04));
assert(n[1] == char(0x53));
assert(n[2] == char(0xDC));
assert(n[3] == char(0x03));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[0] == char(0x00));
assert(n[1] == char(0x56));
assert(n[2] == char(0xDC));
assert(n[3] == char(0x03));
}
{
typedef std::codecvt_utf16<wchar_t, 0x1000> C;
C c;
wchar_t w = 0x40003;
char n[4] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[0] == char(0x04));
assert(n[1] == char(0x53));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[0] == char(0x00));
assert(n[1] == char(0x56));
assert(n[2] == char(0));
assert(n[3] == char(0));
}
{
typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::generate_header> C;
C c;
wchar_t w = 0x40003;
char n[6] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+6);
assert(n[0] == char(0xFE));
assert(n[1] == char(0xFF));
assert(n[2] == char(0xD8));
assert(n[3] == char(0xC0));
assert(n[4] == char(0xDC));
assert(n[5] == char(0x03));
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[0] == char(0xFE));
assert(n[1] == char(0xFF));
assert(n[2] == char(0x10));
assert(n[3] == char(0x05));
assert(n[4] == char(0xDC));
assert(n[5] == char(0x03));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[0] == char(0xFE));
assert(n[1] == char(0xFF));
assert(n[2] == char(0x04));
assert(n[3] == char(0x53));
assert(n[4] == char(0xDC));
assert(n[5] == char(0x03));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[0] == char(0xFE));
assert(n[1] == char(0xFF));
assert(n[2] == char(0x00));
assert(n[3] == char(0x56));
assert(n[4] == char(0xDC));
assert(n[5] == char(0x03));
}
{
typedef std::codecvt_utf16<wchar_t, 0x10FFFF, std::little_endian> C;
C c;
wchar_t w = 0x40003;
char n[4] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[1] == char(0xD8));
assert(n[0] == char(0xC0));
assert(n[3] == char(0xDC));
assert(n[2] == char(0x03));
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[1] == char(0x10));
assert(n[0] == char(0x05));
assert(n[3] == char(0xDC));
assert(n[2] == char(0x03));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[1] == char(0x04));
assert(n[0] == char(0x53));
assert(n[3] == char(0xDC));
assert(n[2] == char(0x03));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[1] == char(0x00));
assert(n[0] == char(0x56));
assert(n[3] == char(0xDC));
assert(n[2] == char(0x03));
}
{
typedef std::codecvt_utf16<wchar_t, 0x1000, std::little_endian> C;
C c;
wchar_t w = 0x40003;
char n[4] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[1] == char(0));
assert(n[0] == char(0));
assert(n[3] == char(0));
assert(n[2] == char(0));
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[1] == char(0));
assert(n[0] == char(0));
assert(n[3] == char(0));
assert(n[2] == char(0));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[1] == char(0x04));
assert(n[0] == char(0x53));
assert(n[3] == char(0));
assert(n[2] == char(0));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[1] == char(0x00));
assert(n[0] == char(0x56));
assert(n[3] == char(0));
assert(n[2] == char(0));
}
{
typedef std::codecvt_utf16<wchar_t, 0x10ffff, std::codecvt_mode(
std::generate_header |
std::little_endian)> C;
C c;
wchar_t w = 0x40003;
char n[6] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+6);
assert(n[1] == char(0xFE));
assert(n[0] == char(0xFF));
assert(n[3] == char(0xD8));
assert(n[2] == char(0xC0));
assert(n[5] == char(0xDC));
assert(n[4] == char(0x03));
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[1] == char(0xFE));
assert(n[0] == char(0xFF));
assert(n[3] == char(0x10));
assert(n[2] == char(0x05));
assert(n[5] == char(0xDC));
assert(n[4] == char(0x03));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[1] == char(0xFE));
assert(n[0] == char(0xFF));
assert(n[3] == char(0x04));
assert(n[2] == char(0x53));
assert(n[5] == char(0xDC));
assert(n[4] == char(0x03));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[1] == char(0xFE));
assert(n[0] == char(0xFF));
assert(n[3] == char(0x00));
assert(n[2] == char(0x56));
assert(n[5] == char(0xDC));
assert(n[4] == char(0x03));
}
template <class CharT>
void TestHelper<CharT, 2>::test() {
// Nothing to do, the conversion in unsupported
}
template <class CharT>
void TestHelper<CharT, 4>::test() {
{
typedef std::codecvt_utf16<CharT> C;
C c;
CharT w = 0x40003;
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 4);
assert(n[0] == char(0xD8));
assert(n[1] == char(0xC0));
assert(n[2] == char(0xDC));
assert(n[3] == char(0x03));
w = 0x1005;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[0] == char(0x10));
assert(n[1] == char(0x05));
assert(n[2] == char(0xDC));
assert(n[3] == char(0x03));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[0] == char(0x04));
assert(n[1] == char(0x53));
assert(n[2] == char(0xDC));
assert(n[3] == char(0x03));
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[0] == char(0x00));
assert(n[1] == char(0x56));
assert(n[2] == char(0xDC));
assert(n[3] == char(0x03));
}
{
typedef std::codecvt_utf16<CharT, 0x1000> C;
C c;
CharT w = 0x40003;
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x1005;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[0] == char(0x04));
assert(n[1] == char(0x53));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[0] == char(0x00));
assert(n[1] == char(0x56));
assert(n[2] == char(0));
assert(n[3] == char(0));
}
{
typedef std::codecvt_utf16<CharT, 0x10ffff, std::generate_header> C;
C c;
CharT w = 0x40003;
char n[6] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 6);
assert(n[0] == char(0xFE));
assert(n[1] == char(0xFF));
assert(n[2] == char(0xD8));
assert(n[3] == char(0xC0));
assert(n[4] == char(0xDC));
assert(n[5] == char(0x03));
w = 0x1005;
r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 4);
assert(n[0] == char(0xFE));
assert(n[1] == char(0xFF));
assert(n[2] == char(0x10));
assert(n[3] == char(0x05));
assert(n[4] == char(0xDC));
assert(n[5] == char(0x03));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 4);
assert(n[0] == char(0xFE));
assert(n[1] == char(0xFF));
assert(n[2] == char(0x04));
assert(n[3] == char(0x53));
assert(n[4] == char(0xDC));
assert(n[5] == char(0x03));
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 4);
assert(n[0] == char(0xFE));
assert(n[1] == char(0xFF));
assert(n[2] == char(0x00));
assert(n[3] == char(0x56));
assert(n[4] == char(0xDC));
assert(n[5] == char(0x03));
}
{
typedef std::codecvt_utf16<CharT, 0x10FFFF, std::little_endian> C;
C c;
CharT w = 0x40003;
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 4);
assert(n[1] == char(0xD8));
assert(n[0] == char(0xC0));
assert(n[3] == char(0xDC));
assert(n[2] == char(0x03));
w = 0x1005;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[1] == char(0x10));
assert(n[0] == char(0x05));
assert(n[3] == char(0xDC));
assert(n[2] == char(0x03));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[1] == char(0x04));
assert(n[0] == char(0x53));
assert(n[3] == char(0xDC));
assert(n[2] == char(0x03));
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[1] == char(0x00));
assert(n[0] == char(0x56));
assert(n[3] == char(0xDC));
assert(n[2] == char(0x03));
}
{
typedef std::codecvt_utf16<CharT, 0x1000, std::little_endian> C;
C c;
CharT w = 0x40003;
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[1] == char(0));
assert(n[0] == char(0));
assert(n[3] == char(0));
assert(n[2] == char(0));
w = 0x1005;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[1] == char(0));
assert(n[0] == char(0));
assert(n[3] == char(0));
assert(n[2] == char(0));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[1] == char(0x04));
assert(n[0] == char(0x53));
assert(n[3] == char(0));
assert(n[2] == char(0));
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[1] == char(0x00));
assert(n[0] == char(0x56));
assert(n[3] == char(0));
assert(n[2] == char(0));
}
{
typedef std::codecvt_utf16<CharT, 0x10ffff,
std::codecvt_mode(std::generate_header |
std::little_endian)>
C;
C c;
CharT w = 0x40003;
char n[6] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 6);
assert(n[1] == char(0xFE));
assert(n[0] == char(0xFF));
assert(n[3] == char(0xD8));
assert(n[2] == char(0xC0));
assert(n[5] == char(0xDC));
assert(n[4] == char(0x03));
w = 0x1005;
r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 4);
assert(n[1] == char(0xFE));
assert(n[0] == char(0xFF));
assert(n[3] == char(0x10));
assert(n[2] == char(0x05));
assert(n[5] == char(0xDC));
assert(n[4] == char(0x03));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 4);
assert(n[1] == char(0xFE));
assert(n[0] == char(0xFF));
assert(n[3] == char(0x04));
assert(n[2] == char(0x53));
assert(n[5] == char(0xDC));
assert(n[4] == char(0x03));
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 6, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 4);
assert(n[1] == char(0xFE));
assert(n[0] == char(0xFF));
assert(n[3] == char(0x00));
assert(n[2] == char(0x56));
assert(n[5] == char(0xDC));
assert(n[4] == char(0x03));
}
}
int main() {
TestHelper<char32_t>::test();
TestHelper<wchar_t>::test();
}

View File

@ -25,432 +25,302 @@
#include <codecvt>
#include <cassert>
int main()
{
{
typedef std::codecvt_utf8<wchar_t> C;
C c;
wchar_t w = 0x40003;
char n[4] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[0] == char(0xF1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x80));
assert(n[3] == char(0x83));
template <class CharT, size_t = sizeof(CharT)>
struct TestHelper;
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+3);
assert(n[0] == char(0xE1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x85));
assert(n[3] == char(0x83));
template <class CharT>
struct TestHelper<CharT, 2> {
static void test();
};
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
assert(n[2] == char(0x85));
assert(n[3] == char(0x83));
template <class CharT>
struct TestHelper<CharT, 4> {
static void test();
};
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
assert(n[1] == char(0x93));
assert(n[2] == char(0x85));
assert(n[3] == char(0x83));
}
{
typedef std::codecvt_utf8<wchar_t, 0x1000> C;
C c;
wchar_t w = 0x40003;
char n[4] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
template <class CharT>
void TestHelper<CharT, 2>::test() {
{
typedef std::codecvt_utf8<CharT> C;
C c;
CharT w = 0x1005;
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 3);
assert(n[0] == char(0xE1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x85));
assert(n[3] == char(0));
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
assert(n[2] == char(0x85));
assert(n[3] == char(0));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 1);
assert(n[0] == char(0x56));
assert(n[1] == char(0x93));
assert(n[2] == char(0x85));
assert(n[3] == char(0));
}
{
typedef std::codecvt_utf8<CharT, 0x1000> C;
C c;
CharT w = 0x1005;
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
assert(n[1] == char(0x93));
assert(n[2] == char(0));
assert(n[3] == char(0));
}
{
typedef std::codecvt_utf8<wchar_t, 0xFFFFFFFF, std::generate_header> C;
C c;
wchar_t w = 0x40003;
char n[7] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+7);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xF1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x80));
assert(n[6] == char(0x83));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+6);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xE1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x85));
assert(n[6] == char(0x83));
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 1);
assert(n[0] == char(0x56));
assert(n[1] == char(0x93));
assert(n[2] == char(0));
assert(n[3] == char(0));
}
{
typedef std::codecvt_utf8<CharT, 0xFFFFFFFF, std::generate_header> C;
C c;
CharT w = 0x1005;
char n[7] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 6);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xE1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x85));
assert(n[6] == char(0));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+5);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xD1));
assert(n[4] == char(0x93));
assert(n[5] == char(0x85));
assert(n[6] == char(0x83));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 5);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xD1));
assert(n[4] == char(0x93));
assert(n[5] == char(0x85));
assert(n[6] == char(0));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0x56));
assert(n[4] == char(0x93));
assert(n[5] == char(0x85));
assert(n[6] == char(0x83));
}
{
typedef std::codecvt_utf8<char32_t> C;
C c;
char32_t w = 0x40003;
char n[4] = {0};
const char32_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[0] == char(0xF1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x80));
assert(n[3] == char(0x83));
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+3);
assert(n[0] == char(0xE1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x85));
assert(n[3] == char(0x83));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
assert(n[2] == char(0x85));
assert(n[3] == char(0x83));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
assert(n[1] == char(0x93));
assert(n[2] == char(0x85));
assert(n[3] == char(0x83));
}
{
typedef std::codecvt_utf8<char32_t, 0x1000> C;
C c;
char32_t w = 0x40003;
char n[4] = {0};
const char32_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
assert(n[1] == char(0x93));
assert(n[2] == char(0));
assert(n[3] == char(0));
}
{
typedef std::codecvt_utf8<char32_t, 0xFFFFFFFF, std::generate_header> C;
C c;
char32_t w = 0x40003;
char n[7] = {0};
const char32_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+7);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xF1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x80));
assert(n[6] == char(0x83));
w = 0x1005;
r = c.out(m, &w, &w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+6);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xE1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x85));
assert(n[6] == char(0x83));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+5);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xD1));
assert(n[4] == char(0x93));
assert(n[5] == char(0x85));
assert(n[6] == char(0x83));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0x56));
assert(n[4] == char(0x93));
assert(n[5] == char(0x85));
assert(n[6] == char(0x83));
}
{
typedef std::codecvt_utf8<char16_t> C;
C c;
char16_t w = 0x1005;
char n[4] = {0};
const char16_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+3);
assert(n[0] == char(0xE1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x85));
assert(n[3] == char(0));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
assert(n[2] == char(0x85));
assert(n[3] == char(0));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
assert(n[1] == char(0x93));
assert(n[2] == char(0x85));
assert(n[3] == char(0));
}
{
typedef std::codecvt_utf8<char16_t, 0x1000> C;
C c;
char16_t w = 0x1005;
char n[4] = {0};
const char16_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
assert(n[1] == char(0x93));
assert(n[2] == char(0));
assert(n[3] == char(0));
}
{
typedef std::codecvt_utf8<char16_t, 0xFFFFFFFF, std::generate_header> C;
C c;
char16_t w = 0x1005;
char n[7] = {0};
const char16_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+6);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xE1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x85));
assert(n[6] == char(0));
w = 0x453;
r = c.out(m, &w, &w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+5);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xD1));
assert(n[4] == char(0x93));
assert(n[5] == char(0x85));
assert(n[6] == char(0));
w = 0x56;
r = c.out(m, &w, &w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w+1);
assert(np == n+4);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0x56));
assert(n[4] == char(0x93));
assert(n[5] == char(0x85));
assert(n[6] == char(0));
}
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 4);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0x56));
assert(n[4] == char(0x93));
assert(n[5] == char(0x85));
assert(n[6] == char(0));
}
}
template <class CharT>
void TestHelper<CharT, 4>::test() {
{
typedef std::codecvt_utf8<CharT> C;
C c;
CharT w = 0x40003;
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 4);
assert(n[0] == char(0xF1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x80));
assert(n[3] == char(0x83));
w = 0x1005;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 3);
assert(n[0] == char(0xE1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x85));
assert(n[3] == char(0x83));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
assert(n[2] == char(0x85));
assert(n[3] == char(0x83));
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 1);
assert(n[0] == char(0x56));
assert(n[1] == char(0x93));
assert(n[2] == char(0x85));
assert(n[3] == char(0x83));
}
{
typedef std::codecvt_utf8<CharT, 0x1000> C;
C c;
CharT w = 0x40003;
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x1005;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::error);
assert(wp == &w);
assert(np == n);
assert(n[0] == char(0));
assert(n[1] == char(0));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
assert(n[2] == char(0));
assert(n[3] == char(0));
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 1);
assert(n[0] == char(0x56));
assert(n[1] == char(0x93));
assert(n[2] == char(0));
assert(n[3] == char(0));
}
{
typedef std::codecvt_utf8<CharT, 0xFFFFFFFF, std::generate_header> C;
C c;
CharT w = 0x40003;
char n[7] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 7);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xF1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x80));
assert(n[6] == char(0x83));
w = 0x1005;
r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 6);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xE1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x85));
assert(n[6] == char(0x83));
w = 0x453;
r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 5);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xD1));
assert(n[4] == char(0x93));
assert(n[5] == char(0x85));
assert(n[6] == char(0x83));
w = 0x56;
r = c.out(m, &w, &w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == &w + 1);
assert(np == n + 4);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0x56));
assert(n[4] == char(0x93));
assert(n[5] == char(0x85));
assert(n[6] == char(0x83));
}
}
int main() {
TestHelper<wchar_t>::test();
TestHelper<char32_t>::test();
TestHelper<char16_t>::test();
}

View File

@ -25,348 +25,220 @@
#include <codecvt>
#include <cassert>
int main()
{
{
typedef std::codecvt_utf8_utf16<wchar_t> C;
C c;
wchar_t w[2] = {0};
char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
wchar_t* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+4);
assert(w[0] == 0xD8C0);
assert(w[1] == 0xDC03);
template <class CharT, size_t = sizeof(CharT)>
struct TestHelper;
template <class CharT>
struct TestHelper<CharT, 2> {
static void test();
};
template <class CharT>
struct TestHelper<CharT, 4> {
static void test();
};
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n+3, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+3);
assert(w[0] == 0x1005);
template <class CharT>
void TestHelper<CharT, 2>::test() {
{
typedef std::codecvt_utf8_utf16<CharT, 0x1000> C;
C c;
CharT w[2] = {0};
char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
CharT* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n + 4, np, w, w + 2, wp);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n+2, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(w[0] == 0x0453);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n + 3, np, w, w + 2, wp);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
n[0] = char(0x56);
r = c.in(m, n, n+1, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(w[0] == 0x0056);
}
{
typedef std::codecvt_utf8_utf16<wchar_t, 0x1000> C;
C c;
wchar_t w[2] = {0};
char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
wchar_t* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n + 2, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 2);
assert(w[0] == 0x0453);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n+3, np, w, w+2, wp);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
n[0] = char(0x56);
r = c.in(m, n, n + 1, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 1);
assert(w[0] == 0x0056);
}
{
typedef std::codecvt_utf8_utf16<CharT, 0x10ffff, std::consume_header> C;
C c;
CharT w[2] = {0};
char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1),
char(0x80), char(0x80), char(0x83)};
CharT* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n + 7, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 2);
assert(np == n + 7);
assert(w[0] == 0xD8C0);
assert(w[1] == 0xDC03);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n+2, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(w[0] == 0x0453);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n + 3, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 3);
assert(w[0] == 0x1005);
n[0] = char(0x56);
r = c.in(m, n, n+1, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(w[0] == 0x0056);
}
{
typedef std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::consume_header> C;
C c;
wchar_t w[2] = {0};
char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
wchar_t* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n+7, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+7);
assert(w[0] == 0xD8C0);
assert(w[1] == 0xDC03);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n + 2, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 2);
assert(w[0] == 0x0453);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n+3, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+3);
assert(w[0] == 0x1005);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n+2, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(w[0] == 0x0453);
n[0] = char(0x56);
r = c.in(m, n, n+1, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(w[0] == 0x0056);
}
{
typedef std::codecvt_utf8_utf16<char32_t> C;
C c;
char32_t w[2] = {0};
char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
char32_t* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+4);
assert(w[0] == 0xD8C0);
assert(w[1] == 0xDC03);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n+3, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+3);
assert(w[0] == 0x1005);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n+2, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(w[0] == 0x0453);
n[0] = char(0x56);
r = c.in(m, n, n+1, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(w[0] == 0x0056);
}
{
typedef std::codecvt_utf8_utf16<char32_t, 0x1000> C;
C c;
char32_t w[2] = {0};
char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
char32_t* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n+3, np, w, w+2, wp);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n+2, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(w[0] == 0x0453);
n[0] = char(0x56);
r = c.in(m, n, n+1, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(w[0] == 0x0056);
}
{
typedef std::codecvt_utf8_utf16<char32_t, 0x10ffff, std::consume_header> C;
C c;
char32_t w[2] = {0};
char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
char32_t* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n+7, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+7);
assert(w[0] == 0xD8C0);
assert(w[1] == 0xDC03);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n+3, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+3);
assert(w[0] == 0x1005);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n+2, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(w[0] == 0x0453);
n[0] = char(0x56);
r = c.in(m, n, n+1, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(w[0] == 0x0056);
}
{
typedef std::codecvt_utf8_utf16<char16_t> C;
C c;
char16_t w[2] = {0};
char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
char16_t* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+4);
assert(w[0] == 0xD8C0);
assert(w[1] == 0xDC03);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n+3, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+3);
assert(w[0] == 0x1005);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n+2, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(w[0] == 0x0453);
n[0] = char(0x56);
r = c.in(m, n, n+1, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(w[0] == 0x0056);
}
{
typedef std::codecvt_utf8_utf16<char16_t, 0x1000> C;
C c;
char16_t w[2] = {0};
char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
char16_t* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n+4, np, w, w+2, wp);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n+3, np, w, w+2, wp);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n+2, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(w[0] == 0x0453);
n[0] = char(0x56);
r = c.in(m, n, n+1, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(w[0] == 0x0056);
}
{
typedef std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::consume_header> C;
C c;
char16_t w[2] = {0};
char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1), char(0x80), char(0x80), char(0x83)};
char16_t* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n+7, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+7);
assert(w[0] == 0xD8C0);
assert(w[1] == 0xDC03);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n+3, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+3);
assert(w[0] == 0x1005);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n+2, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(w[0] == 0x0453);
n[0] = char(0x56);
r = c.in(m, n, n+1, np, w, w+2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(w[0] == 0x0056);
}
n[0] = char(0x56);
r = c.in(m, n, n + 1, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 1);
assert(w[0] == 0x0056);
}
}
template <class CharT>
void TestHelper<CharT, 4>::test() {
{
typedef std::codecvt_utf8_utf16<CharT> C;
C c;
CharT w[2] = {0};
char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
CharT* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n + 4, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 2);
assert(np == n + 4);
assert(w[0] == 0xD8C0);
assert(w[1] == 0xDC03);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n + 3, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 3);
assert(w[0] == 0x1005);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n + 2, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 2);
assert(w[0] == 0x0453);
n[0] = char(0x56);
r = c.in(m, n, n + 1, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 1);
assert(w[0] == 0x0056);
}
{
typedef std::codecvt_utf8_utf16<CharT, 0x1000> C;
C c;
CharT w[2] = {0};
char n[4] = {char(0xF1), char(0x80), char(0x80), char(0x83)};
CharT* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n + 4, np, w, w + 2, wp);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n + 3, np, w, w + 2, wp);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n + 2, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 2);
assert(w[0] == 0x0453);
n[0] = char(0x56);
r = c.in(m, n, n + 1, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 1);
assert(w[0] == 0x0056);
}
{
typedef std::codecvt_utf8_utf16<CharT, 0x10ffff, std::consume_header> C;
C c;
CharT w[2] = {0};
char n[7] = {char(0xEF), char(0xBB), char(0xBF), char(0xF1),
char(0x80), char(0x80), char(0x83)};
CharT* wp = nullptr;
std::mbstate_t m;
const char* np = nullptr;
std::codecvt_base::result r = c.in(m, n, n + 7, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 2);
assert(np == n + 7);
assert(w[0] == 0xD8C0);
assert(w[1] == 0xDC03);
n[0] = char(0xE1);
n[1] = char(0x80);
n[2] = char(0x85);
r = c.in(m, n, n + 3, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 3);
assert(w[0] == 0x1005);
n[0] = char(0xD1);
n[1] = char(0x93);
r = c.in(m, n, n + 2, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 2);
assert(w[0] == 0x0453);
n[0] = char(0x56);
r = c.in(m, n, n + 1, np, w, w + 2, wp);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 1);
assert(w[0] == 0x0056);
}
}
int main() {
#ifndef _WIN32
TestHelper<wchar_t>::test();
#endif
TestHelper<char32_t>::test();
TestHelper<char16_t>::test();
}

View File

@ -25,391 +25,285 @@
#include <codecvt>
#include <cassert>
int main()
{
{
typedef std::codecvt_utf8_utf16<wchar_t> C;
C c;
wchar_t w[2] = {0xD8C0, 0xDC03};
char n[4] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+4);
assert(n[0] == char(0xF1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x80));
assert(n[3] == char(0x83));
template <class CharT, size_t = sizeof(CharT)>
struct TestHelper;
template <class CharT>
struct TestHelper<CharT, 2> {
static void test();
};
template <class CharT>
struct TestHelper<CharT, 4> {
static void test();
};
w[0] = 0x1005;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+3);
assert(n[0] == char(0xE1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x85));
template <class CharT>
void TestHelper<CharT, 2>::test() {
{
typedef std::codecvt_utf8_utf16<CharT> C;
C c;
CharT w[2] = {0xD8C0, 0xDC03};
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 2);
assert(np == n + 4);
assert(n[0] == char(0xF1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x80));
assert(n[3] == char(0x83));
w[0] = 0x453;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
w[0] = 0x1005;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 3);
assert(n[0] == char(0xE1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x85));
w[0] = 0x56;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<wchar_t, 0x1000> C;
C c;
wchar_t w[2] = {0xD8C0, 0xDC03};
char n[4] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
w[0] = 0x453;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
w[0] = 0x1005;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
w[0] = 0x56;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 1);
assert(n[0] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<CharT, 0x1000> C;
C c;
CharT w[2] = {0xD8C0, 0xDC03};
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
w[0] = 0x453;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
w[0] = 0x1005;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
w[0] = 0x56;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::generate_header> C;
C c;
wchar_t w[2] = {0xD8C0, 0xDC03};
char n[7] = {0};
const wchar_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+7);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xF1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x80));
assert(n[6] == char(0x83));
w[0] = 0x453;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
w[0] = 0x1005;
r = c.out(m, w, w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+6);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xE1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x85));
w[0] = 0x56;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 1);
assert(n[0] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<CharT, 0x10ffff, std::generate_header> C;
C c;
CharT w[2] = {0xD8C0, 0xDC03};
char n[7] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 2);
assert(np == n + 7);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xF1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x80));
assert(n[6] == char(0x83));
w[0] = 0x453;
r = c.out(m, w, w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+5);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xD1));
assert(n[4] == char(0x93));
w[0] = 0x1005;
r = c.out(m, w, w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 6);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xE1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x85));
w[0] = 0x56;
r = c.out(m, w, w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+4);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<char32_t> C;
C c;
char32_t w[2] = {0xD8C0, 0xDC03};
char n[4] = {0};
const char32_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+4);
assert(n[0] == char(0xF1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x80));
assert(n[3] == char(0x83));
w[0] = 0x453;
r = c.out(m, w, w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 5);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xD1));
assert(n[4] == char(0x93));
w[0] = 0x1005;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+3);
assert(n[0] == char(0xE1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x85));
w[0] = 0x453;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
w[0] = 0x56;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<char32_t, 0x1000> C;
C c;
char32_t w[2] = {0xD8C0, 0xDC03};
char n[4] = {0};
const char32_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
w[0] = 0x1005;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
w[0] = 0x453;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
w[0] = 0x56;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<char32_t, 0x10ffff, std::generate_header> C;
C c;
char32_t w[2] = {0xD8C0, 0xDC03};
char n[7] = {0};
const char32_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+7);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xF1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x80));
assert(n[6] == char(0x83));
w[0] = 0x1005;
r = c.out(m, w, w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+6);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xE1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x85));
w[0] = 0x453;
r = c.out(m, w, w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+5);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xD1));
assert(n[4] == char(0x93));
w[0] = 0x56;
r = c.out(m, w, w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+4);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<char16_t> C;
C c;
char16_t w[2] = {0xD8C0, 0xDC03};
char n[4] = {0};
const char16_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+4);
assert(n[0] == char(0xF1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x80));
assert(n[3] == char(0x83));
w[0] = 0x1005;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+3);
assert(n[0] == char(0xE1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x85));
w[0] = 0x453;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
w[0] = 0x56;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<char16_t, 0x1000> C;
C c;
char16_t w[2] = {0xD8C0, 0xDC03};
char n[4] = {0};
const char16_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
w[0] = 0x1005;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
w[0] = 0x453;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
w[0] = 0x56;
r = c.out(m, w, w+1, wp, n, n+4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+1);
assert(n[0] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::generate_header> C;
C c;
char16_t w[2] = {0xD8C0, 0xDC03};
char n[7] = {0};
const char16_t* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w+2, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+2);
assert(np == n+7);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xF1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x80));
assert(n[6] == char(0x83));
w[0] = 0x1005;
r = c.out(m, w, w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+6);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xE1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x85));
w[0] = 0x453;
r = c.out(m, w, w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+5);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xD1));
assert(n[4] == char(0x93));
w[0] = 0x56;
r = c.out(m, w, w+1, wp, n, n+7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w+1);
assert(np == n+4);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0x56));
}
w[0] = 0x56;
r = c.out(m, w, w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 4);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0x56));
}
}
template <class CharT>
void TestHelper<CharT, 4>::test() {
{
typedef std::codecvt_utf8_utf16<CharT> C;
C c;
CharT w[2] = {0xD8C0, 0xDC03};
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 2);
assert(np == n + 4);
assert(n[0] == char(0xF1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x80));
assert(n[3] == char(0x83));
w[0] = 0x1005;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 3);
assert(n[0] == char(0xE1));
assert(n[1] == char(0x80));
assert(n[2] == char(0x85));
w[0] = 0x453;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
w[0] = 0x56;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 1);
assert(n[0] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<CharT, 0x1000> C;
C c;
CharT w[2] = {0xD8C0, 0xDC03};
char n[4] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 4, np);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
w[0] = 0x1005;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::error);
assert(wp == w);
assert(np == n);
w[0] = 0x453;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 2);
assert(n[0] == char(0xD1));
assert(n[1] == char(0x93));
w[0] = 0x56;
r = c.out(m, w, w + 1, wp, n, n + 4, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 1);
assert(n[0] == char(0x56));
}
{
typedef std::codecvt_utf8_utf16<CharT, 0x10ffff, std::generate_header> C;
C c;
CharT w[2] = {0xD8C0, 0xDC03};
char n[7] = {0};
const CharT* wp = nullptr;
std::mbstate_t m;
char* np = nullptr;
std::codecvt_base::result r = c.out(m, w, w + 2, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 2);
assert(np == n + 7);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xF1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x80));
assert(n[6] == char(0x83));
w[0] = 0x1005;
r = c.out(m, w, w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 6);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xE1));
assert(n[4] == char(0x80));
assert(n[5] == char(0x85));
w[0] = 0x453;
r = c.out(m, w, w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 5);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0xD1));
assert(n[4] == char(0x93));
w[0] = 0x56;
r = c.out(m, w, w + 1, wp, n, n + 7, np);
assert(r == std::codecvt_base::ok);
assert(wp == w + 1);
assert(np == n + 4);
assert(n[0] == char(0xEF));
assert(n[1] == char(0xBB));
assert(n[2] == char(0xBF));
assert(n[3] == char(0x56));
}
}
int main() {
#ifndef _WIN32
TestHelper<wchar_t>::test();
#endif
TestHelper<char32_t>::test();
TestHelper<char16_t>::test();
}

View File

@ -17,9 +17,39 @@
#include <codecvt>
#include <cassert>
int main()
{
typedef std::codecvt_utf8<wchar_t> Codecvt;
template <class CharT, size_t = sizeof(CharT)>
struct TestHelper;
template <class CharT>
struct TestHelper<CharT, 2> {
static void test();
};
template <class CharT>
struct TestHelper<CharT, 4> {
static void test();
};
template <class CharT>
void TestHelper<CharT, 2>::test() {
static_assert((std::is_same<CharT, wchar_t>::value), "");
{
typedef std::codecvt_utf8<CharT> Codecvt;
typedef std::wstring_convert<Codecvt> Myconv;
Myconv myconv;
assert(myconv.converted() == 0);
std::string bs = myconv.to_bytes(L"\x1005");
assert(myconv.converted() == 1);
bs = myconv.to_bytes(L"\x1005\x65");
assert(myconv.converted() == 2);
std::wstring ws = myconv.from_bytes("\xE1\x80\x85");
assert(myconv.converted() == 3);
}
}
template <class CharT>
void TestHelper<CharT, 4>::test() {
static_assert((std::is_same<CharT, wchar_t>::value), "");
{
typedef std::codecvt_utf8<CharT> Codecvt;
typedef std::wstring_convert<Codecvt> Myconv;
Myconv myconv;
assert(myconv.converted() == 0);
@ -29,4 +59,7 @@ int main()
assert(myconv.converted() == 2);
std::wstring ws = myconv.from_bytes("\xF1\x80\x80\x83");
assert(myconv.converted() == 4);
}
}
int main() { TestHelper<wchar_t>::test(); }

View File

@ -20,20 +20,53 @@
#include <codecvt>
#include <cassert>
int main()
{
{
std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
std::string bs("\xF1\x80\x80\x83");
std::wstring ws = myconv.from_bytes('a');
assert(ws == L"a");
ws = myconv.from_bytes(bs.c_str());
assert(ws == L"\x40003");
ws = myconv.from_bytes(bs);
assert(ws == L"\x40003");
ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
assert(ws == L"\x40003");
ws = myconv.from_bytes("");
assert(ws.size() == 0);
}
template <class CharT, size_t = sizeof(CharT)>
struct TestHelper;
template <class CharT>
struct TestHelper<CharT, 2> {
static void test();
};
template <class CharT>
struct TestHelper<CharT, 4> {
static void test();
};
template <class CharT>
void TestHelper<CharT, 2>::test() {
static_assert((std::is_same<CharT, wchar_t>::value), "");
{
std::wstring_convert<std::codecvt_utf8<CharT> > myconv;
std::string bs("\xE1\x80\x85\x00");
std::wstring ws = myconv.from_bytes('a');
assert(ws == L"a");
ws = myconv.from_bytes(bs.c_str());
assert(ws == L"\x1005");
ws = myconv.from_bytes(bs);
assert(ws == L"\x1005");
ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
assert(ws == L"\x1005");
ws = myconv.from_bytes("");
assert(ws.size() == 0);
}
}
template <class CharT>
void TestHelper<CharT, 4>::test() {
static_assert((std::is_same<CharT, wchar_t>::value), "");
{
std::wstring_convert<std::codecvt_utf8<CharT> > myconv;
std::string bs("\xF1\x80\x80\x83");
std::wstring ws = myconv.from_bytes('a');
assert(ws == L"a");
ws = myconv.from_bytes(bs.c_str());
assert(ws == L"\x40003");
ws = myconv.from_bytes(bs);
assert(ws == L"\x40003");
ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
assert(ws == L"\x40003");
ws = myconv.from_bytes("");
assert(ws.size() == 0);
}
}
int main() { TestHelper<wchar_t>::test(); }

View File

@ -20,20 +20,53 @@
#include <codecvt>
#include <cassert>
int main()
{
{
std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
std::wstring ws(1, L'\x40003');
std::string bs = myconv.to_bytes(ws[0]);
assert(bs == "\xF1\x80\x80\x83");
bs = myconv.to_bytes(ws.c_str());
assert(bs == "\xF1\x80\x80\x83");
bs = myconv.to_bytes(ws);
assert(bs == "\xF1\x80\x80\x83");
bs = myconv.to_bytes(ws.data(), ws.data() + ws.size());
assert(bs == "\xF1\x80\x80\x83");
bs = myconv.to_bytes(L"");
assert(bs.size() == 0);
}
template <class CharT, size_t = sizeof(CharT)>
struct TestHelper;
template <class CharT>
struct TestHelper<CharT, 2> {
static void test();
};
template <class CharT>
struct TestHelper<CharT, 4> {
static void test();
};
template <class CharT>
void TestHelper<CharT, 2>::test() {
static_assert((std::is_same<CharT, wchar_t>::value), "");
{
std::wstring_convert<std::codecvt_utf8<CharT> > myconv;
std::wstring ws(1, CharT(0x1005));
std::string bs = myconv.to_bytes(ws[0]);
assert(bs == "\xE1\x80\x85\x00");
bs = myconv.to_bytes(ws.c_str());
assert(bs == "\xE1\x80\x85\x00");
bs = myconv.to_bytes(ws);
assert(bs == "\xE1\x80\x85\x00");
bs = myconv.to_bytes(ws.data(), ws.data() + ws.size());
assert(bs == "\xE1\x80\x85\x00");
bs = myconv.to_bytes(L"");
assert(bs.size() == 0);
}
}
template <class CharT>
void TestHelper<CharT, 4>::test() {
static_assert((std::is_same<CharT, wchar_t>::value), "");
{
std::wstring_convert<std::codecvt_utf8<CharT> > myconv;
std::wstring ws(1, CharT(0x40003));
std::string bs = myconv.to_bytes(ws[0]);
assert(bs == "\xF1\x80\x80\x83");
bs = myconv.to_bytes(ws.c_str());
assert(bs == "\xF1\x80\x80\x83");
bs = myconv.to_bytes(ws);
assert(bs == "\xF1\x80\x80\x83");
bs = myconv.to_bytes(ws.data(), ws.data() + ws.size());
assert(bs == "\xF1\x80\x80\x83");
bs = myconv.to_bytes(L"");
assert(bs.size() == 0);
}
}
int main() { TestHelper<wchar_t>::test(); }

View File

@ -16,8 +16,10 @@
#include <numeric>
#include <cassert>
#include <climits>
#include <cstdint>
#include <cstdlib> // for rand()
#include <iostream>
#include <type_traits>
constexpr struct {
int x;
@ -36,21 +38,24 @@ constexpr struct {
template <typename Input1, typename Input2, typename Output>
constexpr bool test0(Input1 in1, Input2 in2, Output out)
constexpr bool test0(int in1, int in2, int out)
{
static_assert((std::is_same<Output, decltype(std::gcd(in1, in2))>::value), "" );
static_assert((std::is_same<Output, decltype(std::gcd(in2, in1))>::value), "" );
return out == std::gcd(in1, in2) ? true : (std::abort(), false);
auto value1 = static_cast<Input1>(in1);
auto value2 = static_cast<Input2>(in2);
static_assert(std::is_same_v<Output, decltype(std::gcd(value1, value2))>, "");
static_assert(std::is_same_v<Output, decltype(std::gcd(value2, value1))>, "");
assert(static_cast<Output>(out) == std::gcd(value1, value2));
return true;
}
template <typename Input1, typename Input2 = Input1>
constexpr bool do_test(int = 0)
{
using S1 = typename std::make_signed<Input1>::type;
using S2 = typename std::make_signed<Input2>::type;
using U1 = typename std::make_unsigned<Input1>::type;
using U2 = typename std::make_unsigned<Input2>::type;
using S1 = std::make_signed_t<Input1>;
using S2 = std::make_signed_t<Input2>;
using U1 = std::make_unsigned_t<Input1>;
using U2 = std::make_unsigned_t<Input2>;
bool accumulate = true;
for (auto TC : Cases) {
{ // Test with two signed types
@ -103,15 +108,15 @@ int main()
assert(do_test<long>(non_cce));
assert(do_test<long long>(non_cce));
static_assert(do_test< int8_t>(), "");
static_assert(do_test<int16_t>(), "");
static_assert(do_test<int32_t>(), "");
static_assert(do_test<int64_t>(), "");
static_assert(do_test<std::int8_t>(), "");
static_assert(do_test<std::int16_t>(), "");
static_assert(do_test<std::int32_t>(), "");
static_assert(do_test<std::int64_t>(), "");
assert(do_test< int8_t>(non_cce));
assert(do_test<int16_t>(non_cce));
assert(do_test<int32_t>(non_cce));
assert(do_test<int64_t>(non_cce));
assert(do_test<std::int8_t>(non_cce));
assert(do_test<std::int16_t>(non_cce));
assert(do_test<std::int32_t>(non_cce));
assert(do_test<std::int64_t>(non_cce));
static_assert(do_test<signed char, int>(), "");
static_assert(do_test<int, signed char>(), "");
@ -133,8 +138,8 @@ int main()
// LWG#2837
{
auto res = std::gcd((int64_t)1234, (int32_t)-2147483648);
static_assert( std::is_same<decltype(res), std::common_type<int64_t, int32_t>::type>::value, "");
assert(res == 2);
auto res = std::gcd(static_cast<std::int64_t>(1234), INT32_MIN);
static_assert(std::is_same_v<decltype(res), std::int64_t>, "");
assert(res == 2);
}
}

View File

@ -11,12 +11,14 @@
// <numeric>
// template<class _M, class _N>
// constexpr common_type_t<_M,_N> gcd(_M __m, _N __n)
// constexpr common_type_t<_M,_N> lcm(_M __m, _N __n)
#include <numeric>
#include <cassert>
#include <climits>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <type_traits>
constexpr struct {
int x;
@ -34,21 +36,24 @@ constexpr struct {
};
template <typename Input1, typename Input2, typename Output>
constexpr bool test0(Input1 in1, Input2 in2, Output out)
constexpr bool test0(int in1, int in2, int out)
{
static_assert((std::is_same<Output, decltype(std::lcm(Input1(0), Input2(0)))>::value), "" );
static_assert((std::is_same<Output, decltype(std::lcm(Input2(0), Input1(0)))>::value), "" );
return out == std::lcm(in1, in2) ? true : (std::abort(), false);
auto value1 = static_cast<Input1>(in1);
auto value2 = static_cast<Input2>(in2);
static_assert(std::is_same_v<Output, decltype(std::lcm(value1, value2))>, "");
static_assert(std::is_same_v<Output, decltype(std::lcm(value2, value1))>, "");
assert(static_cast<Output>(out) == std::lcm(value1, value2));
return true;
}
template <typename Input1, typename Input2 = Input1>
constexpr bool do_test(int = 0)
{
using S1 = typename std::make_signed<Input1>::type;
using S2 = typename std::make_signed<Input2>::type;
using U1 = typename std::make_unsigned<Input1>::type;
using U2 = typename std::make_unsigned<Input2>::type;
using S1 = std::make_signed_t<Input1>;
using S2 = std::make_signed_t<Input2>;
using U1 = std::make_unsigned_t<Input1>;
using U2 = std::make_unsigned_t<Input2>;
bool accumulate = true;
for (auto TC : Cases) {
{ // Test with two signed types
@ -101,15 +106,15 @@ int main()
assert(do_test<long>(non_cce));
assert(do_test<long long>(non_cce));
static_assert(do_test< int8_t>(), "");
static_assert(do_test<int16_t>(), "");
static_assert(do_test<int32_t>(), "");
static_assert(do_test<int64_t>(), "");
static_assert(do_test<std::int8_t>(), "");
static_assert(do_test<std::int16_t>(), "");
static_assert(do_test<std::int32_t>(), "");
static_assert(do_test<std::int64_t>(), "");
assert(do_test< int8_t>(non_cce));
assert(do_test<int16_t>(non_cce));
assert(do_test<int32_t>(non_cce));
assert(do_test<int64_t>(non_cce));
assert(do_test<std::int8_t>(non_cce));
assert(do_test<std::int16_t>(non_cce));
assert(do_test<std::int32_t>(non_cce));
assert(do_test<std::int64_t>(non_cce));
static_assert(do_test<signed char, int>(), "");
static_assert(do_test<int, signed char>(), "");
@ -131,9 +136,9 @@ int main()
// LWG#2837
{
auto res1 = std::lcm((int64_t)1234, (int32_t)-2147483648);
(void) std::lcm<int, unsigned long>(INT_MIN, 2); // this used to trigger UBSAN
static_assert( std::is_same<decltype(res1), std::common_type<int64_t, int32_t>::type>::value, "");
assert(res1 == 1324997410816LL);
auto res1 = std::lcm(static_cast<std::int64_t>(1234), INT32_MIN);
(void)std::lcm(INT_MIN, 2UL); // this used to trigger UBSAN
static_assert(std::is_same_v<decltype(res1), std::int64_t>, "");
assert(res1 == 1324997410816LL);
}
}

View File

@ -27,39 +27,61 @@ test(const char_type* A,
typename std::regex_traits<char_type>::char_class_type expected,
bool icase = false)
{
typedef typename std::regex_traits<char_type>::char_class_type char_class_type;
std::regex_traits<char_type> t;
typedef forward_iterator<const char_type*> F;
assert(t.lookup_classname(F(A), F(A + t.length(A)), icase) == expected);
char_class_type result = t.lookup_classname(F(A), F(A + t.length(A)), icase);
assert(result == expected);
}
template <class char_type>
void
test_w(const char_type* A,
typename std::regex_traits<char_type>::char_class_type expected,
bool icase = false)
{
typedef typename std::regex_traits<char_type>::char_class_type char_class_type;
std::regex_traits<char_type> t;
typedef forward_iterator<const char_type*> F;
char_class_type result = t.lookup_classname(F(A), F(A + t.length(A)), icase);
assert((result & expected) == expected);
LIBCPP_ASSERT((expected | std::regex_traits<char_type>::__regex_word) == result);
const bool matches_underscore = t.isctype('_', result);
if (result != expected)
assert(matches_underscore && "expected to match underscore");
else
assert(!matches_underscore && "should not match underscore");
}
int main()
{
// if __regex_word is not distinct from all the classes, bad things happen
// See https://bugs.llvm.org/show_bug.cgi?id=26476 for an example.
assert((std::ctype_base::space & std::regex_traits<char>::__regex_word) == 0);
assert((std::ctype_base::print & std::regex_traits<char>::__regex_word) == 0);
assert((std::ctype_base::cntrl & std::regex_traits<char>::__regex_word) == 0);
assert((std::ctype_base::upper & std::regex_traits<char>::__regex_word) == 0);
assert((std::ctype_base::lower & std::regex_traits<char>::__regex_word) == 0);
assert((std::ctype_base::alpha & std::regex_traits<char>::__regex_word) == 0);
assert((std::ctype_base::digit & std::regex_traits<char>::__regex_word) == 0);
assert((std::ctype_base::punct & std::regex_traits<char>::__regex_word) == 0);
assert((std::ctype_base::xdigit & std::regex_traits<char>::__regex_word) == 0);
assert((std::ctype_base::blank & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::space & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::print & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::cntrl & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::upper & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::lower & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::alpha & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::digit & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::punct & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::xdigit & std::regex_traits<char>::__regex_word) == 0);
LIBCPP_ASSERT((std::ctype_base::blank & std::regex_traits<char>::__regex_word) == 0);
test("d", std::ctype_base::digit);
test("D", std::ctype_base::digit);
test("d", std::ctype_base::digit, true);
test("D", std::ctype_base::digit, true);
test("w", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower);
test("W", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower);
test("w", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower, true);
test("W", std::regex_traits<char>::__regex_word | std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower, true);
test_w("w", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower);
test_w("W", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower);
test_w("w", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower, true);
test_w("W", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower, true);
test("s", std::ctype_base::space);
test("S", std::ctype_base::space);
@ -140,13 +162,13 @@ int main()
test(L"d", std::ctype_base::digit, true);
test(L"D", std::ctype_base::digit, true);
test(L"w", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
test_w(L"w", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower);
test(L"W", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
test_w(L"W", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower);
test(L"w", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
test_w(L"w", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower, true);
test(L"W", std::regex_traits<wchar_t>::__regex_word | std::ctype_base::alnum
test_w(L"W", std::ctype_base::alnum
| std::ctype_base::upper | std::ctype_base::lower, true);
test(L"s", std::ctype_base::space);

View File

@ -27,16 +27,17 @@
template <class S, class SV>
void
test(SV sv, unsigned pos, unsigned n)
test(SV sv, std::size_t pos, std::size_t n)
{
typedef typename S::traits_type T;
typedef typename S::allocator_type A;
typedef typename S::size_type Size;
if (pos <= sv.size())
{
S s2(sv, pos, n);
S s2(sv, static_cast<Size>(pos), static_cast<Size>(n));
LIBCPP_ASSERT(s2.__invariants());
assert(pos <= sv.size());
unsigned rlen = std::min<unsigned>(sv.size() - pos, n);
std::size_t rlen = std::min(sv.size() - pos, n);
assert(s2.size() == rlen);
assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0);
assert(s2.get_allocator() == A());
@ -47,7 +48,7 @@ test(SV sv, unsigned pos, unsigned n)
{
try
{
S s2(sv, pos, n);
S s2(sv, static_cast<Size>(pos), static_cast<Size>(n));
assert(false);
}
catch (std::out_of_range&)
@ -60,15 +61,16 @@ test(SV sv, unsigned pos, unsigned n)
template <class S, class SV>
void
test(SV sv, unsigned pos, unsigned n, const typename S::allocator_type& a)
test(SV sv, std::size_t pos, std::size_t n, const typename S::allocator_type& a)
{
typedef typename S::traits_type T;
typedef typename S::size_type Size;
if (pos <= sv.size())
{
S s2(sv, pos, n, a);
S s2(sv, static_cast<Size>(pos), static_cast<Size>(n), a);
LIBCPP_ASSERT(s2.__invariants());
assert(pos <= sv.size());
unsigned rlen = std::min<unsigned>(sv.size() - pos, n);
std::size_t rlen = std::min(sv.size() - pos, n);
assert(s2.size() == rlen);
assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0);
assert(s2.get_allocator() == a);
@ -79,7 +81,7 @@ test(SV sv, unsigned pos, unsigned n, const typename S::allocator_type& a)
{
try
{
S s2(sv, pos, n, a);
S s2(sv, static_cast<Size>(pos), static_cast<Size>(n), a);
assert(false);
}
catch (std::out_of_range&)

View File

@ -1,67 +0,0 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <string_view>
// void clear() noexcept
#include <string_view>
#include <cassert>
#include "test_macros.h"
template<typename CharT>
void test ( const CharT *s, size_t len ) {
typedef std::basic_string_view<CharT> SV;
{
SV sv1 ( s );
assert ( sv1.size() == len );
assert ( sv1.data() == s );
sv1.clear ();
assert ( sv1.data() == nullptr );
assert ( sv1.size() == 0 );
assert ( sv1 == SV());
}
}
#if TEST_STD_VER > 11
constexpr size_t test_ce ( size_t n ) {
typedef std::basic_string_view<char> SV;
SV sv1{ "ABCDEFGHIJKL", n };
sv1.clear();
return sv1.size();
}
#endif
int main () {
test ( "ABCDE", 5 );
test ( "a", 1 );
test ( "", 0 );
test ( L"ABCDE", 5 );
test ( L"a", 1 );
test ( L"", 0 );
#if TEST_STD_VER >= 11
test ( u"ABCDE", 5 );
test ( u"a", 1 );
test ( u"", 0 );
test ( U"ABCDE", 5 );
test ( U"a", 1 );
test ( U"", 0 );
#endif
#if TEST_STD_VER > 11
static_assert ( test_ce (5) == 0, "" );
#endif
}

View File

@ -0,0 +1,22 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <thread>
// template <class Rep, class Period>
// void sleep_for(const chrono::duration<Rep, Period>& rel_time);
// The std::this_thread::sleep_for test requires POSIX specific headers and
// is therefore non-standard. For this reason the test lives under the 'libcxx'
// subdirectory.
int main()
{
}

View File

@ -107,5 +107,11 @@ int main()
assert((a.inner_allocator() ==
std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6))));
}
// Test for LWG2782
{
static_assert(!std::is_convertible<A1<int>, A2<int>>::value, "");
static_assert(!std::is_convertible<
std::scoped_allocator_adaptor<A1<int>>,
std::scoped_allocator_adaptor<A2<int>>>::value, "");
}
}

View File

@ -416,7 +416,7 @@ void throws_in_constructor_test()
ThrowsOnCopy() = default;
bool operator()() const {
assert(false);
#if defined(_LIBCPP_MSVC)
#if defined(TEST_COMPILER_C1XX)
__assume(0);
#else
__builtin_unreachable();

View File

@ -11,7 +11,8 @@
// class function<R(ArgTypes...)>
// function(const function& f);
// function(const function& f);
// function(const function&& f);
#include <functional>
#include <memory>

View File

@ -63,6 +63,7 @@ int main()
assert(A::count == 1);
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
assert(f.target<int>() == nullptr);
}
assert(A::count == 0);
{
@ -70,6 +71,7 @@ int main()
assert(A::count == 0);
assert(f.target<int(*)(int)>());
assert(f.target<A>() == 0);
assert(f.target<int>() == nullptr);
}
assert(A::count == 0);
{
@ -77,6 +79,7 @@ int main()
assert(A::count == 1);
assert(f.target<A>());
assert(f.target<int(*)(int)>() == 0);
assert(f.target<int>() == nullptr);
}
assert(A::count == 0);
{
@ -84,6 +87,7 @@ int main()
assert(A::count == 0);
assert(f.target<int(*)(int)>());
assert(f.target<A>() == 0);
assert(f.target<int>() == nullptr);
}
assert(A::count == 0);
}

View File

@ -49,6 +49,10 @@ struct Bar : public Foo {
};
struct PrivateBase : private std::enable_shared_from_this<PrivateBase> {
};
int main()
{
{ // https://bugs.llvm.org/show_bug.cgi?id=18843
@ -74,6 +78,12 @@ int main()
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
{
typedef std::shared_ptr<PrivateBase> APtr;
typedef std::weak_ptr<PrivateBase> WeakAPtr;
APtr a1 = std::make_shared<PrivateBase>();
assert(a1.use_count() == 1);
}
// Test LWG issue 2529. Only reset '__weak_ptr_' when it's already expired.
// http://cplusplus.github.io/LWG/lwg-active.html#2529.
// Test two different ways:

View File

@ -120,7 +120,9 @@ int main()
static_assert((!std::is_convertible<ConstFunction, Function>::value), "");
static_assert((!std::is_convertible<ConstFunction, Function*>::value), "");
static_assert((!std::is_convertible<ConstFunction, Function&>::value), "");
static_assert((!std::is_convertible<ConstFunction, Function>::value), "");
#if TEST_STD_VER >= 11
static_assert((!std::is_convertible<ConstFunction, Function&&>::value), "");
#endif
static_assert((!std::is_convertible<Function*, ConstFunction>::value), "");
static_assert((!std::is_convertible<Function&, ConstFunction>::value), "");
static_assert((!std::is_convertible<ConstFunction, ConstFunction>::value), "");

View File

@ -11,7 +11,9 @@
// is_trivially_copyable
// XFAIL: gcc-4.9
// These compilers have not implemented Core 2094 which makes volatile
// qualified types trivially copyable.
// XFAIL: clang-3, clang-4, apple-clang, gcc
#include <type_traits>
#include <cassert>
@ -22,13 +24,13 @@ void test_is_trivially_copyable()
{
static_assert( std::is_trivially_copyable<T>::value, "");
static_assert( std::is_trivially_copyable<const T>::value, "");
static_assert(!std::is_trivially_copyable<volatile T>::value, "");
static_assert(!std::is_trivially_copyable<const volatile T>::value, "");
static_assert( std::is_trivially_copyable<volatile T>::value, "");
static_assert( std::is_trivially_copyable<const volatile T>::value, "");
#if TEST_STD_VER > 14
static_assert( std::is_trivially_copyable_v<T>, "");
static_assert( std::is_trivially_copyable_v<const T>, "");
static_assert(!std::is_trivially_copyable_v<volatile T>, "");
static_assert(!std::is_trivially_copyable_v<const volatile T>, "");
static_assert( std::is_trivially_copyable_v<volatile T>, "");
static_assert( std::is_trivially_copyable_v<const volatile T>, "");
#endif
}

View File

@ -11,22 +11,27 @@
#include <bitset>
#ifndef _LIBCPP_CSTDDEF
#error <cstddef> has not been included
#endif
#ifndef _LIBCPP_STRING
#error <string> has not been included
#endif
#ifndef _LIBCPP_STDEXCEPT
#error <stdexcept> has not been included
#endif
#ifndef _LIBCPP_IOSFWD
#error <iosfwd> has not been included
#endif
template <class> void test_typedef() {}
int main()
{
{ // test for <cstddef>
std::ptrdiff_t p; ((void)p);
std::size_t s; ((void)s);
std::nullptr_t np; ((void)np);
}
{ // test for <string>
std::string s; ((void)s);
}
{ // test for <stdexcept>
std::logic_error le("blah"); ((void)le);
std::runtime_error re("blah"); ((void)re);
}
{ // test for <iosfwd>
test_typedef<std::ios>();
test_typedef<std::wios>();
test_typedef<std::istream>();
test_typedef<std::ostream>();
test_typedef<std::iostream>();
}
}

View File

@ -15,6 +15,10 @@
// ~tuple();
// C++17 added:
// The destructor of tuple shall be a trivial destructor
// if (is_trivially_destructible_v<Types> && ...) is true.
#include <tuple>
#include <string>
#include <cassert>

View File

@ -15,6 +15,10 @@
// ~pair()
// C++17 added:
// The destructor of pair shall be a trivial destructor
// if (is_trivially_destructible_v<T1> && is_trivially_destructible_v<T2>) is true.
#include <utility>
#include <type_traits>

View File

@ -94,6 +94,16 @@ void test_call_operator_forwarding() {
using Fn = ForwardingCallObject;
Fn obj{};
const Fn &cobj = obj;
{ // test call operator forwarding - no variant
std::visit(obj);
assert(Fn::check_call<>(CT_NonConst | CT_LValue));
std::visit(cobj);
assert(Fn::check_call<>(CT_Const | CT_LValue));
std::visit(std::move(obj));
assert(Fn::check_call<>(CT_NonConst | CT_RValue));
std::visit(std::move(cobj));
assert(Fn::check_call<>(CT_Const | CT_RValue));
}
{ // test call operator forwarding - single variant, single arg
using V = std::variant<int>;
V v(42);

View File

@ -5,6 +5,7 @@
#include <cassert>
#include "test_macros.h"
#include "test_workarounds.h"
#if TEST_STD_VER >= 11
@ -14,7 +15,9 @@ template <bool, class T>
struct DepType : T {};
struct NullBase {
#ifndef TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
protected:
#endif // !TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
NullBase() = default;
NullBase(NullBase const&) = default;
NullBase& operator=(NullBase const&) = default;
@ -81,7 +84,9 @@ struct TestBase {
++assigned; ++value_assigned;
return *this;
}
#ifndef TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
protected:
#endif // !TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
~TestBase() {
assert(value != -999); assert(alive > 0);
--alive; ++destroyed; value = -999;
@ -144,7 +149,9 @@ struct ValueBase {
}
//~ValueBase() { assert(value != -999); value = -999; }
int value;
#ifndef TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
protected:
#endif // !TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
constexpr static int check_value(int const& val) {
#if TEST_STD_VER < 14
return val == -1 || val == 999 ? (TEST_THROW(42), 0) : val;
@ -197,7 +204,9 @@ struct TrivialValueBase {
template <bool Dummy = true, typename std::enable_if<Dummy && !Explicit, bool>::type = true>
constexpr TrivialValueBase(std::initializer_list<int>& il, int = 0) : value(static_cast<int>(il.size())) {}
int value;
#ifndef TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
protected:
#endif // !TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
constexpr TrivialValueBase() noexcept : value(0) {}
};

View File

@ -6,7 +6,11 @@
#define DEFINE_EXPLICIT
#endif
#ifndef DEFINE_CONSTEXPR
#ifdef TEST_WORKAROUND_EDG_EXPLICIT_CONSTEXPR
#define DEFINE_CONSTEXPR
#else // TEST_WORKAROUND_EDG_EXPLICIT_CONSTEXPR
#define DEFINE_CONSTEXPR constexpr
#endif // TEST_WORKAROUND_EDG_EXPLICIT_CONSTEXPR
#endif
#ifndef DEFINE_ASSIGN_CONSTEXPR
#if TEST_STD_VER >= 14

View File

@ -25,7 +25,7 @@ def sanitize(p):
"""
Some of the tests restrict permissions to induce failures.
Before we delete the test enviroment, we have to walk it and re-raise the
Before we delete the test environment, we have to walk it and re-raise the
permissions.
"""
def clean_recursive(root_p):

View File

@ -227,7 +227,7 @@ struct scoped_test_env
}
static inline void fs_helper_run(std::string const& raw_cmd) {
// check that the fs test root in the enviroment matches what we were
// check that the fs test root in the environment matches what we were
// compiled with.
static bool checked = checkDynamicTestRoot();
((void)checked);
@ -246,7 +246,7 @@ struct scoped_test_env
std::abort();
}
if (std::string(fs_root) != LIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT) {
std::printf("ERROR: LIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT enviroment variable"
std::printf("ERROR: LIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT environment variable"
" must have the same value as when the test was compiled.\n");
std::printf(" Current Value: '%s'\n", fs_root);
std::printf(" Expected Value: '%s'\n", LIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT);

View File

@ -13,11 +13,13 @@
// This header is force-included when running the libc++ tests against the
// MSVC standard library.
// Silence warnings about CRT machinery.
#define _CRT_SECURE_NO_WARNINGS
#ifndef _LIBCXX_IN_DEVCRT
// Silence warnings about CRT machinery.
#define _CRT_SECURE_NO_WARNINGS
// Avoid assertion dialogs.
#define _CRT_SECURE_INVALID_PARAMETER(EXPR) ::abort()
// Avoid assertion dialogs.
#define _CRT_SECURE_INVALID_PARAMETER(EXPR) ::abort()
#endif // _LIBCXX_IN_DEVCRT
#include <crtdbg.h>
#include <stdlib.h>
@ -31,6 +33,7 @@
#define _MSVC_STL_VER 42
#endif
#ifndef _LIBCXX_IN_DEVCRT
struct AssertionDialogAvoider {
AssertionDialogAvoider() {
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
@ -42,6 +45,7 @@ struct AssertionDialogAvoider {
};
const AssertionDialogAvoider assertion_dialog_avoider{};
#endif // _LIBCXX_IN_DEVCRT
// MSVC frontend only configurations
#if !defined(__clang__)
@ -66,16 +70,18 @@ const AssertionDialogAvoider assertion_dialog_avoider{};
// MSVC has quick_exit() and at_quick_exit().
#define _LIBCPP_HAS_QUICK_EXIT
// atomic_is_lock_free.pass.cpp needs this VS 2015 Update 2 fix.
#define _ENABLE_ATOMIC_ALIGNMENT_FIX
#ifndef _LIBCXX_IN_DEVCRT
// atomic_is_lock_free.pass.cpp needs this VS 2015 Update 2 fix.
#define _ENABLE_ATOMIC_ALIGNMENT_FIX
// Enable features that /std:c++latest removes by default.
#define _HAS_AUTO_PTR_ETC 1
#define _HAS_FUNCTION_ASSIGN 1
#define _HAS_OLD_IOSTREAMS_MEMBERS 1
// Enable features that /std:c++latest removes by default.
#define _HAS_AUTO_PTR_ETC 1
#define _HAS_FUNCTION_ASSIGN 1
#define _HAS_OLD_IOSTREAMS_MEMBERS 1
// Silence warnings about raw pointers and other unchecked iterators.
#define _SCL_SECURE_NO_WARNINGS
// Silence warnings about raw pointers and other unchecked iterators.
#define _SCL_SECURE_NO_WARNINGS
#endif // _LIBCXX_IN_DEVCRT
#include <ciso646>

View File

@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03
// Verify TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK.
#include <type_traits>
#include "test_workarounds.h"
struct X {
X(int) {}
X(X&&) = default;
X& operator=(X&&) = default;
private:
X(const X&) = default;
X& operator=(const X&) = default;
};
void PushFront(X&&) {}
template<class T = int>
auto test(int) -> decltype(PushFront(std::declval<T>()), std::true_type{});
auto test(long) -> std::false_type;
int main() {
#if defined(TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK)
static_assert(!decltype(test(0))::value, "");
#else
static_assert(decltype(test(0))::value, "");
#endif
}

Some files were not shown because too many files have changed in this diff Show More