virtual const char*
what() const throw();
+#if __cplusplus >= 201103L
+ // Define the new members required by C++11,
+ // even though the error_code cannot be stored.
+
+ explicit
+ failure(const string& __s, const error_code&) noexcept
+ : failure(__s)
+ { }
+
+ explicit
+ failure(const char* __s, const error_code& = error_code{})
+ : failure(string(__s))
+ { }
+
+ // Stand-in for system_error::code() but returning by value.
+ error_code code() const noexcept { return error_code{}; }
+#endif
+
private:
string _M_msg;
};
// <http://www.gnu.org/licenses/>.
// { dg-do run { target c++11 } }
-// { dg-require-effective-target cxx11-abi }
#include <ios>
#include <testsuite_hooks.h>
using test_type = std::ios_base::failure;
+#if _GLIBCXX_USE_CXX11_ABI
static_assert( std::is_base_of<std::system_error, test_type>::value, "base" );
+#endif
void
test01()
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++11 } }
+
+#include <ios>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::error_code ec, def_ec;
+#if _GLIBCXX_USE_CXX11_ABI
+ // For the new ABI code() should return the constructor argument.
+ ec = std::make_error_code(std::errc::executable_format_error);
+ def_ec = std::io_errc::stream;
+#else
+ // For the old ABI code() always returns a default-constructed error_code.
+#endif
+ std::ios_base::failure e1("string literal");
+ VERIFY( e1.code() == def_ec );
+ std::ios_base::failure e2(std::string("std::string"));
+ VERIFY( e2.code() == def_ec );
+ std::ios_base::failure e3("string literal", ec);
+ VERIFY( e3.code() == ec );
+ std::ios_base::failure e4(std::string("std::string"), ec);
+ VERIFY( e4.code() == ec );
+}
+
+int
+main()
+{
+ test01();
+}