Files
clang-p2996/libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout-imbue.sh.cpp
Louis Dionne 257eb74524 [libc++] Simplify how the global stream tests are written (#66842)
Instead of relying on Bash, use the builtin Lit commands whenever
possible. The motivation is to stop running %t.exe behind Bash, which
breaks on macOS 13.5 with SIP enabled because DYLD_LIBRARY_PATH isn't
forwarded to the underlying process when running through a protected
process.

For more details, see [1].

[1]: https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html
2023-09-20 09:33:16 -04:00

43 lines
1.2 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <iostream>
// wostream wcout;
// UNSUPPORTED: no-wide-characters
// RUN: %{build}
// RUN: %{exec} %t.exe > %t.actual
// RUN: echo -n zzzz > %t.expected
// RUN: diff %t.expected %t.actual
#include <iostream>
struct custom_codecvt : std::codecvt<wchar_t, char, std::mbstate_t> {
using base = std::codecvt<wchar_t, char, std::mbstate_t>;
protected:
result do_out(std::mbstate_t&, const wchar_t *from, const wchar_t *from_end,
const wchar_t *&from_next, char *to, char *to_end, char *&to_next) const {
while (from != from_end && to != to_end) {
++from;
*to++ = 'z';
}
from_next = from;
to_next = to;
return ok;
}
};
int main(int, char**) {
std::locale loc(std::locale::classic(), new custom_codecvt);
std::wcout.imbue(loc);
std::wcout << L"1234";
return 0;
}