This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
This patch has been in my tree being compiled and regtested on x86_64-unknown-linux for a while.
This patch is presented for discussion because it moves the regular old ios_base::failure from the .cc to inline to prevent multiple definitions with the 0x version. In C++-0x ios_base::failure derives from system_error.
Finally, we should figure out how to populate these exceptions with good indicators of what the error was.
Index: src/Makefile.in
===================================================================
--- src/Makefile.in (revision 150991)
+++ src/Makefile.in (working copy)
@@ -77,13 +77,13 @@
pool_allocator.cc mt_allocator.cc codecvt.cc compatibility.cc \
complex_io.cc ctype.cc debug.cc functexcept.cc hash_tr1.cc \
hash_c++0x.cc globals_io.cc hashtable_tr1.cc \
- hashtable_c++0x.cc ios.cc ios_failure.cc ios_init.cc \
+ hashtable_c++0x.cc ios.cc ios_failure_c++0x.cc ios_init.cc \
ios_locale.cc limits.cc limits_c++0x.cc list.cc debug_list.cc \
locale.cc locale_init.cc locale_facets.cc localename.cc \
math_stubs_float.cc math_stubs_long_double.cc stdexcept.cc \
- strstream.cc system_error.cc tree.cc allocator-inst.cc \
- concept-inst.cc fstream-inst.cc ext-inst.cc ios-inst.cc \
- iostream-inst.cc istream-inst.cc istream.cc locale-inst.cc \
+ stdexcept_c++0x.cc strstream.cc system_error.cc tree.cc \
+ allocator-inst.cc concept-inst.cc fstream-inst.cc ext-inst.cc \
+ ios-inst.cc iostream-inst.cc istream-inst.cc istream.cc locale-inst.cc \
misc-inst.cc ostream-inst.cc sstream-inst.cc streambuf-inst.cc \
streambuf.cc string-inst.cc valarray-inst.cc wlocale-inst.cc \
wstring-inst.cc mutex.cc condition_variable.cc chrono.cc \
@@ -104,11 +104,11 @@
mt_allocator.lo codecvt.lo compatibility.lo complex_io.lo \
ctype.lo debug.lo functexcept.lo hash_tr1.lo hash_c++0x.lo \
globals_io.lo hashtable_tr1.lo hashtable_c++0x.lo ios.lo \
- ios_failure.lo ios_init.lo ios_locale.lo limits.lo \
+ ios_failure_c++0x.lo ios_init.lo ios_locale.lo limits.lo \
limits_c++0x.lo list.lo debug_list.lo locale.lo locale_init.lo \
locale_facets.lo localename.lo math_stubs_float.lo \
- math_stubs_long_double.lo stdexcept.lo strstream.lo \
- system_error.lo tree.lo allocator-inst.lo concept-inst.lo \
+ math_stubs_long_double.lo stdexcept.lo stdexcept_c++0x.lo \
+ strstream.lo system_error.lo tree.lo allocator-inst.lo concept-inst.lo \
fstream-inst.lo ext-inst.lo ios-inst.lo iostream-inst.lo \
istream-inst.lo istream.lo locale-inst.lo misc-inst.lo \
ostream-inst.lo sstream-inst.lo streambuf-inst.lo streambuf.lo \
@@ -403,7 +403,7 @@
hashtable_tr1.cc \
hashtable_c++0x.cc \
ios.cc \
- ios_failure.cc \
+ ios_failure_c++0x.cc \
ios_init.cc \
ios_locale.cc \
limits.cc \
@@ -417,6 +417,7 @@
math_stubs_float.cc \
math_stubs_long_double.cc \
stdexcept.cc \
+ stdexcept_c++0x.cc \
strstream.cc \
system_error.cc \
tree.cc \
@@ -880,6 +881,11 @@
hashtable_c++0x.o: hashtable_c++0x.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
+ios_failure_c++0x.lo: ios_failure_c++0x.cc
+ $(LTCXXCOMPILE) -std=gnu++0x -c $<
+ios_failure_c++0x.o: ios_failure_c++0x.cc
+ $(CXXCOMPILE) -std=gnu++0x -c $<
+
limits_c++0x.lo: limits_c++0x.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
limits_c++0x.o: limits_c++0x.cc
@@ -915,6 +921,11 @@
future.o: future.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
+stdexcept_c++0x.lo: stdexcept_c++0x.cc
+ $(LTCXXCOMPILE) -std=gnu++0x -c $<
+stdexcept_c++0x.o: stdexcept_c++0x.cc
+ $(CXXCOMPILE) -std=gnu++0x -c $<
+
# Use special rules for compatibility-ldbl.cc compilation, as we need to
# pass -mlong-double-64.
@GLIBCXX_LDBL_COMPAT_TRUE@compatibility-ldbl.lo: compatibility-ldbl.cc
Index: src/ios_failure.cc
===================================================================
--- src/ios_failure.cc (revision 150991)
+++ src/ios_failure.cc (working copy)
@@ -1,44 +0,0 @@
-// Iostreams base classes -*- C++ -*-
-
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2009
-// 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.
-
-// Under Section 7 of GPL version 3, you are granted additional
-// permissions described in the GCC Runtime Library Exception, version
-// 3.1, as published by the Free Software Foundation.
-
-// You should have received a copy of the GNU General Public License and
-// a copy of the GCC Runtime Library Exception along with this program;
-// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
-// <http://www.gnu.org/licenses/>.
-
-//
-// ISO C++ 14882: 27.4.2.1.1 Class ios_base::failure
-//
-
-#include <ios>
-
-_GLIBCXX_BEGIN_NAMESPACE(std)
-
- ios_base::failure::failure(const string& __str) throw()
- : _M_msg(__str) { }
-
- ios_base::failure::~failure() throw()
- { }
-
- const char*
- ios_base::failure::what() const throw()
- { return _M_msg.c_str(); }
-
-_GLIBCXX_END_NAMESPACE
Index: src/ios_failure_c++0x.cc
===================================================================
--- src/ios_failure_c++0x.cc (revision 150316)
+++ src/ios_failure_c++0x.cc (working copy)
@@ -28,17 +28,42 @@
//
#include <ios>
+#include <system_error>
+#include <cstring>
+namespace
+{
+ using std::string;
+
+ struct iostream_error_category : public std::error_category
+ {
+ virtual const char*
+ name() const
+ { return "iostream"; }
+
+ virtual string
+ message(int i) const
+ {
+ // XXX locale issues: how does one get or set loc.
+ // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc)
+ return string(strerror(i));
+ }
+ };
+
+ const iostream_error_category iostream_category_instance;
+}
+
_GLIBCXX_BEGIN_NAMESPACE(std)
- ios_base::failure::failure(const string& __str) throw()
- : _M_msg(__str) { }
+ const error_category&
+ iostream_category() { return iostream_category_instance; }
- ios_base::failure::~failure() throw()
- { }
-
- const char*
- ios_base::failure::what() const throw()
- { return _M_msg.c_str(); }
+ error_code
+ make_error_code(io_errc __e)
+ { return error_code(static_cast<int>(__e), iostream_category()); }
+ error_condition
+ make_error_condition(io_errc __e)
+ { return error_condition(static_cast<int>(__e), iostream_category()); }
+
_GLIBCXX_END_NAMESPACE
Index: src/stdexcept_c++0x.cc
===================================================================
--- src/stdexcept_c++0x.cc (revision 0)
+++ src/stdexcept_c++0x.cc (revision 0)
@@ -0,0 +1,61 @@
+// Methods for Exception Support for -*- C++ -*-
+
+// Copyright (C) 2009
+// 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+//
+// ISO C++ 14882: 19.1 Exception classes
+//
+
+#include <stdexcept>
+
+_GLIBCXX_BEGIN_NAMESPACE(std)
+
+ logic_error::logic_error(const char* __arg)
+ : exception(), _M_msg(__arg) { }
+
+ domain_error::domain_error(const char* __arg)
+ : logic_error(__arg) { }
+
+ invalid_argument::invalid_argument(const char* __arg)
+ : logic_error(__arg) { }
+
+ length_error::length_error(const char* __arg)
+ : logic_error(__arg) { }
+
+ out_of_range::out_of_range(const char* __arg)
+ : logic_error(__arg) { }
+
+ runtime_error::runtime_error(const char* __arg)
+ : exception(), _M_msg(__arg) { }
+
+ range_error::range_error(const char* __arg)
+ : runtime_error(__arg) { }
+
+ overflow_error::overflow_error(const char* __arg)
+ : runtime_error(__arg) { }
+
+ underflow_error::underflow_error(const char* __arg)
+ : runtime_error(__arg) { }
+
+_GLIBCXX_END_NAMESPACE
Index: src/Makefile.am
===================================================================
--- src/Makefile.am (revision 150991)
+++ src/Makefile.am (working copy)
@@ -150,7 +150,7 @@
hashtable_tr1.cc \
hashtable_c++0x.cc \
ios.cc \
- ios_failure.cc \
+ ios_failure_c++0x.cc \
ios_init.cc \
ios_locale.cc \
limits.cc \
@@ -164,6 +164,7 @@
math_stubs_float.cc \
math_stubs_long_double.cc \
stdexcept.cc \
+ stdexcept_c++0x.cc \
strstream.cc \
system_error.cc \
tree.cc \
@@ -268,6 +269,11 @@
hashtable_c++0x.o: hashtable_c++0x.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
+ios_failure_c++0x.lo: ios_failure_c++0x.cc
+ $(LTCXXCOMPILE) -std=gnu++0x -c $<
+ios_failure_c++0x.o: ios_failure_c++0x.cc
+ $(CXXCOMPILE) -std=gnu++0x -c $<
+
limits_c++0x.lo: limits_c++0x.cc
$(LTCXXCOMPILE) -std=gnu++0x -c $<
limits_c++0x.o: limits_c++0x.cc
@@ -303,6 +309,11 @@
future.o: future.cc
$(CXXCOMPILE) -std=gnu++0x -c $<
+stdexcept_c++0x.lo: stdexcept_c++0x.cc
+ $(LTCXXCOMPILE) -std=gnu++0x -c $<
+stdexcept_c++0x.o: stdexcept_c++0x.cc
+ $(CXXCOMPILE) -std=gnu++0x -c $<
+
if GLIBCXX_LDBL_COMPAT
# Use special rules for compatibility-ldbl.cc compilation, as we need to
# pass -mlong-double-64.
Index: include/std/system_error
===================================================================
--- include/std/system_error (revision 150991)
+++ include/std/system_error (working copy)
@@ -308,17 +308,13 @@
system_error(error_code __ec, const string& __what)
: runtime_error(__what), _M_code(__ec) { }
-
- /*
- * TODO: Add const char* ctors to all exceptions.
- *
- * system_error(error_code __ec, const char* __what)
- * : runtime_error(__what), _M_code(__ec) { }
- *
- * system_error(int __v, const error_category& __ecat, const char* __what)
- * : runtime_error(__what), _M_code(error_code(__v, __ecat)) { }
- */
+ system_error(error_code __ec, const char* __what)
+ : runtime_error(__what), _M_code(__ec) { }
+
+ system_error(int __v, const error_category& __ecat, const char* __what)
+ : runtime_error(__what), _M_code(error_code(__v, __ecat)) { }
+
system_error(int __v, const error_category& __ecat)
: runtime_error(""), _M_code(error_code(__v, __ecat)) { }
Index: include/std/stdexcept
===================================================================
--- include/std/stdexcept (revision 150991)
+++ include/std/stdexcept (working copy)
@@ -59,6 +59,12 @@
explicit
logic_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ /** Takes a character string describing the error. */
+ explicit
+ logic_error(const char* __arg);
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
virtual
~logic_error() throw();
@@ -74,6 +80,9 @@
{
public:
explicit domain_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ explicit domain_error(const char* __arg);
+#endif // __GXX_EXPERIMENTAL_CXX0X__
};
/** Thrown to report invalid arguments to functions. */
@@ -81,6 +90,9 @@
{
public:
explicit invalid_argument(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ explicit invalid_argument(const char* __arg);
+#endif // __GXX_EXPERIMENTAL_CXX0X__
};
/** Thrown when an object is constructed that would exceed its maximum
@@ -89,6 +101,9 @@
{
public:
explicit length_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ explicit length_error(const char* __arg);
+#endif // __GXX_EXPERIMENTAL_CXX0X__
};
/** This represents an argument whose value is not within the expected
@@ -97,6 +112,9 @@
{
public:
explicit out_of_range(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ explicit out_of_range(const char* __arg);
+#endif // __GXX_EXPERIMENTAL_CXX0X__
};
/** Runtime errors represent problems outside the scope of a program;
@@ -113,6 +131,12 @@
explicit
runtime_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ /** Takes a character string describing the error. */
+ explicit
+ runtime_error(const char* __arg);
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
virtual
~runtime_error() throw();
@@ -127,6 +151,9 @@
{
public:
explicit range_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ explicit range_error(const char* __arg);
+#endif // __GXX_EXPERIMENTAL_CXX0X__
};
/** Thrown to indicate arithmetic overflow. */
@@ -134,6 +161,9 @@
{
public:
explicit overflow_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ explicit overflow_error(const char* __arg);
+#endif // __GXX_EXPERIMENTAL_CXX0X__
};
/** Thrown to indicate arithmetic underflow. */
@@ -141,6 +171,9 @@
{
public:
explicit underflow_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ explicit underflow_error(const char* __arg);
+#endif // __GXX_EXPERIMENTAL_CXX0X__
};
// @} group exceptions
Index: include/bits/ios_base.h
===================================================================
--- include/bits/ios_base.h (revision 150991)
+++ include/bits/ios_base.h (working copy)
@@ -41,6 +41,9 @@
#include <ext/atomicity.h>
#include <bits/localefwd.h>
#include <bits/locale_classes.h>
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+# include <system_error> // For C++0X ios_base::failure
+#endif
#ifndef _GLIBCXX_STDIO_MACROS
# include <cstdio> // For SEEK_CUR, SEEK_END
@@ -194,6 +197,35 @@
_S_ios_seekdir_end = 1L << 16
};
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+
+ /**
+ *
+ */
+ enum class io_errc
+ {
+ stream = 1
+ };
+
+ /**
+ * DR 890.
+ */
+ _GLIBCXX_CONST const error_category& iostream_category() throw ();
+
+ /**
+ *
+ */
+ error_code
+ make_error_code(io_errc __e);
+
+ /**
+ *
+ */
+ error_condition
+ make_error_condition(io_errc __e);
+
+#endif
+
// 27.4.2 Class ios_base
/**
* @brief The base of the I/O class hierarchy.
@@ -208,10 +240,38 @@
{
public:
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+
/**
* @brief These are thrown to indicate problems with io.
* @ingroup exceptions
*
+ * 27.5.2.1.1 Class ios_base::failure
+ */
+ class failure : public system_error
+ {
+ public:
+ explicit
+ failure(const string& __str,
+ const error_code& __ec = make_error_code(io_errc::stream))
+ : system_error(__ec, __str) { }
+
+ explicit
+ failure(const char* __str,
+ const error_code& __ec = make_error_code(io_errc::stream))
+ : system_error(__ec, __str) { }
+
+ virtual const char*
+ what() const throw()
+ { return system_error::what(); }
+ };
+
+#else
+
+ /**
+ * @brief These are thrown to indicate problems with io.
+ * @ingroup exceptions
+ *
* 27.4.2.1.1 Class ios_base::failure
*/
class failure : public exception
@@ -220,20 +280,24 @@
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 48. Use of non-existent exception constructor
explicit
- failure(const string& __str) throw();
+ failure(const string& __str) throw()
+ : _M_msg(__str) { }
// This declaration is not useless:
// http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Vague-Linkage.html
virtual
- ~failure() throw();
+ ~failure() throw() { }
virtual const char*
- what() const throw();
+ what() const throw()
+ { return _M_msg.c_str(); }
private:
string _M_msg;
};
+#endif
+
// 27.4.2.1.2 Type ios_base::fmtflags
/**
* @brief This is a bitmask type.
Attachment:
CL_cpp0x_ios_base_failure
Description: video/flv
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |