| 1 | // Copyright (C) 2020-2025 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 | // { dg-do run { target c++11 } } |
| 19 | |
| 20 | #include <ios> |
| 21 | #include <testsuite_hooks.h> |
| 22 | |
| 23 | void |
| 24 | test01() |
| 25 | { |
| 26 | std::error_code ec, def_ec; |
| 27 | #if _GLIBCXX_USE_CXX11_ABI |
| 28 | // For the new ABI code() should return the constructor argument. |
| 29 | ec = std::make_error_code(std::errc::executable_format_error); |
| 30 | def_ec = std::io_errc::stream; |
| 31 | #else |
| 32 | // For the old ABI code() always returns a default-constructed error_code. |
| 33 | #endif |
| 34 | std::ios_base::failure e1("string literal"); |
| 35 | VERIFY( e1.code() == def_ec ); |
| 36 | std::ios_base::failure e2(std::string("std::string")); |
| 37 | VERIFY( e2.code() == def_ec ); |
| 38 | std::ios_base::failure e3("string literal", ec); |
| 39 | VERIFY( e3.code() == ec ); |
| 40 | std::ios_base::failure e4(std::string("std::string"), ec); |
| 41 | VERIFY( e4.code() == ec ); |
| 42 | } |
| 43 | |
| 44 | [[gnu::noinline,gnu::noipa]] |
| 45 | const std::error_category& |
| 46 | get_iostream_category() |
| 47 | { return std::iostream_category(); } |
| 48 | |
| 49 | void |
| 50 | test02() |
| 51 | { |
| 52 | auto ec = std::make_error_code(std::io_errc::stream); |
| 53 | VERIFY( ec.category() == get_iostream_category() ); |
| 54 | } |
| 55 | |
| 56 | int |
| 57 | main() |
| 58 | { |
| 59 | test01(); |
| 60 | test02(); |
| 61 | } |