65 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// <ostream>10 11// template <class charT, class traits = char_traits<charT> >12// class basic_ostream::sentry;13 14// explicit sentry(basic_ostream<charT,traits>& os);15 16#include <ostream>17#include <cassert>18 19#include "test_macros.h"20 21int sync_called = 0;22 23template <class CharT>24struct testbuf125 : public std::basic_streambuf<CharT>26{27 testbuf1() {}28 29protected:30 31 int virtual sync()32 {33 ++sync_called;34 return 1;35 }36};37 38int main(int, char**)39{40 {41 std::ostream os((std::streambuf*)0);42 std::ostream::sentry s(os);43 assert(!bool(s));44 }45 {46 testbuf1<char> sb;47 std::ostream os(&sb);48 std::ostream::sentry s(os);49 assert(bool(s));50 }51 {52 testbuf1<char> sb;53 std::ostream os(&sb);54 testbuf1<char> sb2;55 std::ostream os2(&sb2);56 os.tie(&os2);57 assert(sync_called == 0);58 std::ostream::sentry s(os);59 assert(bool(s));60 assert(sync_called == 1);61 }62 63 return 0;64}65