72 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// <ios>10 11// template <class charT, class traits> class basic_ios12 13// void clear(iostate state = goodbit);14 15#include <ios>16#include <streambuf>17#include <cassert>18 19#include "test_macros.h"20 21struct testbuf : public std::streambuf {};22 23int main(int, char**)24{25 {26 std::ios ios(0);27 ios.clear();28 assert(ios.rdstate() == std::ios::badbit);29#ifndef TEST_HAS_NO_EXCEPTIONS30 try31 {32 ios.exceptions(std::ios::badbit);33 assert(false);34 }35 catch (...)36 {37 }38 try39 {40 ios.clear();41 assert(false);42 }43 catch (std::ios::failure&)44 {45 assert(ios.rdstate() == std::ios::badbit);46 }47 try48 {49 ios.clear(std::ios::eofbit);50 assert(false);51 }52 catch (std::ios::failure&)53 {54 assert(ios.rdstate() == (std::ios::eofbit | std::ios::badbit));55 }56#endif57 }58 {59 testbuf sb;60 std::ios ios(&sb);61 ios.clear();62 assert(ios.rdstate() == std::ios::goodbit);63 ios.exceptions(std::ios::badbit);64 ios.clear();65 assert(ios.rdstate() == std::ios::goodbit);66 ios.clear(std::ios::eofbit);67 assert(ios.rdstate() == std::ios::eofbit);68 }69 70 return 0;71}72