brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · fbc0bb4 Raw
81 lines · cpp
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-exception6//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_CONVERT12 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++1417// explicit wbuffer_convert(streambuf* bytebuf = nullptr, Codecvt* pcvt = new Codecvt,18//                          state_type state = state_type()); // before C++2019// wbuffer_convert() : wbuffer_convert(nullptr) {} // C++2020// explicit wbuffer_convert(streambuf* bytebuf, Codecvt* pcvt = new Codecvt,21//                          state_type state = state_type()); // C++2022 23// XFAIL: no-wide-characters24 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 >= 1133#include "test_convertible.h"34#endif35 36int main(int, char**)37{38    globalMemCounter.reset();39    typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > B;40#if TEST_STD_VER > 1141    static_assert(!std::is_convertible<std::streambuf*, B>::value, "");42    static_assert( std::is_constructible<B, std::streambuf*>::value, "");43#endif44    {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 >= 1173    {74      static_assert(test_convertible<B>(), "");75      static_assert(!test_convertible<B, std::streambuf*>(), "");76    }77#endif78 79    return 0;80}81