1// Copyright (C) 2003, 2009 2// Free Software Foundation, Inc. 3// 4// This file is part of the GNU ISO C++ Library. This library is free 5// software; you can redistribute it and/or modify it under the 6// terms of the GNU General Public License as published by the 7// Free Software Foundation; either version 3, or (at your option) 8// any later version. 9 10// This library is distributed in the hope that it will be useful, 11// but WITHOUT ANY WARRANTY; without even the implied warranty of 12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13// GNU General Public License for more details. 14 15// You should have received a copy of the GNU General Public License along 16// with this library; see the file COPYING3. If not see 17// <http://www.gnu.org/licenses/>. 18 19 20#include <sstream> 21#include <testsuite_hooks.h> 22 23// libstdc++/10093 24template<typename T> 25void test_failbit() 26{ 27 using namespace std; 28 bool test __attribute__((unused)) = true; 29 30 istringstream stream("jaylib - champion sound"); 31 stream.exceptions(ios_base::failbit); 32 33 try 34 { 35 T i; 36 stream >> i; 37 VERIFY( false ); 38 } 39 catch (const ios_base::failure&) 40 { 41 // stream should set failbit and throw ios_base::failure. 42 VERIFY( stream.fail() ); 43 VERIFY( !stream.bad() ); 44 VERIFY( !stream.eof() ); 45 } 46 catch(...) 47 { VERIFY( false ); } 48} 49 50int main() 51{ 52 test_failbit<bool>(); 53 test_failbit<short>(); 54 test_failbit<unsigned short>(); 55 test_failbit<int>(); 56 test_failbit<unsigned int>(); 57 test_failbit<long>(); 58 test_failbit<unsigned long>(); 59 60 test_failbit<float>(); 61 test_failbit<double>(); 62 63 test_failbit<void*>(); 64 65 return 0; 66} 67