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