1fcbbd964SMartin Storsjö //===----------------------------------------------------------------------===//
2fcbbd964SMartin Storsjö //
3fcbbd964SMartin Storsjö // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4fcbbd964SMartin Storsjö // See https://llvm.org/LICENSE.txt for license information.
5fcbbd964SMartin Storsjö // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6fcbbd964SMartin Storsjö //
7fcbbd964SMartin Storsjö //===----------------------------------------------------------------------===//
8fcbbd964SMartin Storsjö
9fcbbd964SMartin Storsjö // <iostream>
10fcbbd964SMartin Storsjö
11f9bd4597SLouis Dionne // wostream wcerr;
12fcbbd964SMartin Storsjö
13fcbbd964SMartin Storsjö // UNSUPPORTED: no-wide-characters
14fcbbd964SMartin Storsjö
15fcbbd964SMartin Storsjö // RUN: %{build}
16*257eb745SLouis Dionne // RUN: %{exec} %t.exe 2> %t.actual
17*257eb745SLouis Dionne // RUN: echo -n zzzz > %t.expected
18*257eb745SLouis Dionne // RUN: diff %t.expected %t.actual
19fcbbd964SMartin Storsjö
20fcbbd964SMartin Storsjö #include <iostream>
21fcbbd964SMartin Storsjö
22fcbbd964SMartin Storsjö struct custom_codecvt : std::codecvt<wchar_t, char, std::mbstate_t> {
23fcbbd964SMartin Storsjö using base = std::codecvt<wchar_t, char, std::mbstate_t>;
24fcbbd964SMartin Storsjö protected:
do_outcustom_codecvt25fcbbd964SMartin Storsjö result do_out(std::mbstate_t&, const wchar_t *from, const wchar_t *from_end,
26fcbbd964SMartin Storsjö const wchar_t *&from_next, char *to, char *to_end, char *&to_next) const {
27fcbbd964SMartin Storsjö while (from != from_end && to != to_end) {
28fcbbd964SMartin Storsjö ++from;
29fcbbd964SMartin Storsjö *to++ = 'z';
30fcbbd964SMartin Storsjö }
31fcbbd964SMartin Storsjö from_next = from;
32fcbbd964SMartin Storsjö to_next = to;
33fcbbd964SMartin Storsjö return ok;
34fcbbd964SMartin Storsjö }
35fcbbd964SMartin Storsjö };
36fcbbd964SMartin Storsjö
main(int,char **)37fcbbd964SMartin Storsjö int main(int, char**) {
38fcbbd964SMartin Storsjö std::locale loc(std::locale::classic(), new custom_codecvt);
39fcbbd964SMartin Storsjö std::wcerr.imbue(loc);
40fcbbd964SMartin Storsjö std::wcerr << L"1234";
41fcbbd964SMartin Storsjö return 0;
42fcbbd964SMartin Storsjö }
43