system_error::what

Rodrigo Rivas rodrigorivascosta@gmail.com
Tue Aug 3 10:46:00 GMT 2010


Hi all.

The std::system_error from C++0x is lacking the "what()" function.
The attached patch adds it.
Also, it looks like the testsuite works fine with it.

What do you think?

Regards
--
Rodrigo.
-------------- next part --------------
Index: libstdc++-v3/src/system_error.cc
===================================================================
--- libstdc++-v3/src/system_error.cc	(revision 162786)
+++ libstdc++-v3/src/system_error.cc	(working copy)
@@ -80,6 +80,23 @@
   
   system_error::~system_error() throw() { }
 
+  const char *
+  system_error::what() const throw()
+  {
+    if (_M_string.empty()) {
+      try {
+        _M_string = runtime_error::what();
+        if (!_M_string.empty())
+          _M_string += ": ";
+        _M_string += _M_code.message();
+      }
+      catch (...) {
+        return runtime_error::what();
+      }
+    }
+    return _M_string.c_str();
+  }
+
   error_condition 
   error_category::default_error_condition(int __i) const
   { return error_condition(__i, *this); }
Index: libstdc++-v3/include/std/system_error
===================================================================
--- libstdc++-v3/include/std/system_error	(revision 162786)
+++ libstdc++-v3/include/std/system_error	(working copy)
@@ -308,6 +308,7 @@
   {
   private:
     error_code 	_M_code;
+    mutable string      _M_string;
 
   public:
     system_error(error_code __ec = error_code())
@@ -336,6 +337,8 @@
 
     const error_code& 
     code() const throw() { return _M_code; }
+    virtual const char *
+    what() const throw();
   };
 
 _GLIBCXX_END_NAMESPACE
Index: libstdc++-v3/config/abi/pre/gnu.ver
===================================================================
--- libstdc++-v3/config/abi/pre/gnu.ver	(revision 162786)
+++ libstdc++-v3/config/abi/pre/gnu.ver	(working copy)
@@ -1028,6 +1028,7 @@
     _ZTVSt12system_error;
     _ZNSt12system_errorD*Ev;
     _ZNSt12system_errorC*;
+    _ZNKSt12system_error4whatEv;
 
     _ZNKSt4hashISt10error_codeEclES0_;
 


More information about the Libstdc++ mailing list