brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 6d91d71 Raw
58 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;13 14// basic_ostream& flush();15 16#include <ostream>17#include <cassert>18 19#include "test_macros.h"20 21int sync_called = 0;22 23template <class CharT>24class testbuf25    : public std::basic_streambuf<CharT>26{27public:28    testbuf()29    {30    }31 32protected:33 34    virtual int35        sync()36        {37            if (sync_called++ == 1)38                return -1;39            return 0;40        }41};42 43int main(int, char**)44{45    {46        testbuf<char> sb;47        std::ostream os(&sb);48        os.flush();49        assert(os.good());50        assert(sync_called == 1);51        os.flush();52        assert(os.bad());53        assert(sync_called == 2);54    }55 56  return 0;57}58