| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// <locale> |
| 10 |
|
| 11 |
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT -D_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT |
| 12 |
|
| 13 |
// wbuffer_convert<Codecvt, Elem, Tr> |
| 14 |
|
| 15 |
// wbuffer_convert(streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt, |
| 16 |
// state_type state = state_type()); // before C++14 |
| 17 |
// explicit wbuffer_convert(streambuf* bytebuf = nullptr, Codecvt* pcvt = new Codecvt, |
| 18 |
// state_type state = state_type()); // before C++20 |
| 19 |
// wbuffer_convert() : wbuffer_convert(nullptr) {} // C++20 |
| 20 |
// explicit wbuffer_convert(streambuf* bytebuf, Codecvt* pcvt = new Codecvt, |
| 21 |
// state_type state = state_type()); // C++20 |
| 22 |
|
| 23 |
// XFAIL: no-wide-characters |
| 24 |
|
| 25 |
#include <locale> |
| 26 |
#include <codecvt> |
| 27 |
#include <sstream> |
| 28 |
#include <cassert> |
| 29 |
|
| 30 |
#include "test_macros.h" |
| 31 |
#include "count_new.h" |
| 32 |
#if TEST_STD_VER >= 11 |
| 33 |
#include "test_convertible.h" |
| 34 |
#endif |
| 35 |
|
| 36 |
int main(int, char**) |
| 37 |
{ |
| 38 |
globalMemCounter.reset(); |
| 39 |
typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > B; |
| 40 |
#if TEST_STD_VER > 11 |
| 41 |
static_assert(!std::is_convertible<std::streambuf*, B>::value, ""); |
| 42 |
static_assert( std::is_constructible<B, std::streambuf*>::value, ""); |
| 43 |
#endif |
| 44 |
{ |
| 45 |
B b; |
| 46 |
assert(b.rdbuf() == nullptr); |
| 47 |
assert(globalMemCounter.checkOutstandingNewNotEq(0)); |
| 48 |
} |
| 49 |
assert(globalMemCounter.checkOutstandingNewEq(0)); |
| 50 |
{ |
| 51 |
std::stringstream s; |
| 52 |
B b(s.rdbuf()); |
| 53 |
assert(b.rdbuf() == s.rdbuf()); |
| 54 |
assert(globalMemCounter.checkOutstandingNewNotEq(0)); |
| 55 |
} |
| 56 |
assert(globalMemCounter.checkOutstandingNewEq(0)); |
| 57 |
{ |
| 58 |
std::stringstream s; |
| 59 |
B b(s.rdbuf(), new std::codecvt_utf8<wchar_t>); |
| 60 |
assert(b.rdbuf() == s.rdbuf()); |
| 61 |
assert(globalMemCounter.checkOutstandingNewNotEq(0)); |
| 62 |
} |
| 63 |
assert(globalMemCounter.checkOutstandingNewEq(0)); |
| 64 |
{ |
| 65 |
std::stringstream s; |
| 66 |
B b(s.rdbuf(), new std::codecvt_utf8<wchar_t>, std::mbstate_t()); |
| 67 |
assert(b.rdbuf() == s.rdbuf()); |
| 68 |
assert(globalMemCounter.checkOutstandingNewNotEq(0)); |
| 69 |
} |
| 70 |
assert(globalMemCounter.checkOutstandingNewEq(0)); |
| 71 |
|
| 72 |
#if TEST_STD_VER >= 11 |
| 73 |
{ |
| 74 |
static_assert(test_convertible<B>(), ""); |
| 75 |
static_assert(!test_convertible<B, std::streambuf*>(), ""); |
| 76 |
} |
| 77 |
#endif |
| 78 |
|
| 79 |
return 0; |
| 80 |
} |