system_error::what
Rodrigo Rivas
rodrigorivascosta@gmail.com
Tue Aug 3 16:21:00 GMT 2010
What about this? It is ready for delegation.
By the way, I copied your patches to the testsuites. But I don't
understand why there was the call to the "runtime_error::what()" in
cons-1.cc. I don't think this should be there.
Also, I added the missing constructors with "const char *". Don't know
if there was a reason of omitting them.
Regards.
--
Rodrigo.
-------------- next part --------------
Index: include/std/system_error
===================================================================
--- include/std/system_error (revisión: 162786)
+++ include/std/system_error (copia de trabajo)
@@ -308,30 +308,37 @@
{
private:
error_code _M_code;
+ static string __make_error_string(const error_code &__ec, string __what)
+ {
+ try {
+ if (!__what.empty())
+ __what += ": ";
+ __what += __ec.message();
+ }
+ catch (...) {
+ }
+ return __what;
+ }
public:
+ /* TODO: when constructor delegation is ready, all other constructors should delegate to these two */
system_error(error_code __ec = error_code())
- : runtime_error(""), _M_code(__ec) { }
+ : runtime_error(__make_error_string(__ec, "")), _M_code(__ec) { }
system_error(error_code __ec, const string& __what)
- : runtime_error(__what), _M_code(__ec) { }
+ : runtime_error(__make_error_string(__ec, __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(__make_error_string(__ec, __what)), _M_code(__ec) { }
system_error(int __v, const error_category& __ecat)
- : runtime_error(""), _M_code(error_code(__v, __ecat)) { }
+ : runtime_error(__make_error_string(error_code(__v, __ecat), "")), _M_code(error_code(__v, __ecat)) { }
system_error(int __v, const error_category& __ecat, const string& __what)
- : runtime_error(__what), _M_code(error_code(__v, __ecat)) { }
+ : runtime_error(__make_error_string(error_code(__v, __ecat), __what)), _M_code(error_code(__v, __ecat)) { }
+ system_error(int __v, const error_category& __ecat, const char* __what)
+ : runtime_error(__make_error_string(error_code(__v, __ecat), __what)), _M_code(error_code(__v, __ecat)) { }
+
virtual ~system_error() throw();
const error_code&
Index: testsuite/19_diagnostics/system_error/cons-1.cc
===================================================================
--- testsuite/19_diagnostics/system_error/cons-1.cc (revisión: 162786)
+++ testsuite/19_diagnostics/system_error/cons-1.cc (copia de trabajo)
@@ -18,7 +18,7 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <cstring>
+#include <string>
#include <system_error>
#include <testsuite_hooks.h>
@@ -33,14 +33,14 @@
{
std::system_error err1(e, s);
VERIFY( err1.code() == e );
- VERIFY( std::strcmp(err1.runtime_error::what(), s.c_str()) == 0 );
+ VERIFY( std::string(err1.what()).find(s) != std::string::npos );
}
// 2
{
std::system_error err2(95, std::system_category(), s);
VERIFY( err2.code() == std::error_code(95, std::system_category()) );
- VERIFY( std::strcmp(err2.runtime_error::what(), s.c_str()) == 0 );
+ VERIFY( std::string((err2.what(), s)).find(s) != std::string::npos );
}
return 0;
Index: testsuite/19_diagnostics/system_error/what-1.cc
===================================================================
--- testsuite/19_diagnostics/system_error/what-1.cc (revisión: 162786)
+++ testsuite/19_diagnostics/system_error/what-1.cc (copia de trabajo)
@@ -22,7 +22,6 @@
#include <string>
#include <system_error>
-#include <cstring>
#include <testsuite_hooks.h>
using namespace std;
@@ -39,8 +38,8 @@
// 2
system_error obj2(error_code(), s);
- VERIFY( strcmp(obj1.what(), s.data()) == 0 );
- VERIFY( strcmp(obj2.what(), s.data()) == 0 );
+ VERIFY( string(obj1.what()).find(s.data()) != string::npos );
+ VERIFY( string(obj2.what()).find(s.data()) != string::npos );
}
void test02()
@@ -49,7 +48,7 @@
string s("lack of sunlight error");
system_error x(error_code(), s);
- VERIFY( strcmp(x.what(), s.data()) == 0 );
+ VERIFY( string(x.what()).find(s.data()) != string::npos );
}
int main(void)
Index: testsuite/19_diagnostics/system_error/what-2.cc
===================================================================
--- testsuite/19_diagnostics/system_error/what-2.cc (revisión: 162786)
+++ testsuite/19_diagnostics/system_error/what-2.cc (copia de trabajo)
@@ -22,7 +22,6 @@
#include <string>
#include <system_error>
-#include <cstring>
#include <testsuite_hooks.h>
// libstdc++/2089
@@ -38,7 +37,7 @@
try
{ throw fuzzy_logic(); }
catch(const fuzzy_logic& obj)
- { VERIFY( std::strcmp("whoa", obj.what()) == 0 ); }
+ { VERIFY( std::string(obj.what()).find("whoa") != std::string::npos ); }
catch(...)
{ VERIFY( false ); }
}
Index: testsuite/19_diagnostics/system_error/what-big.cc
===================================================================
--- testsuite/19_diagnostics/system_error/what-big.cc (revisión: 162786)
+++ testsuite/19_diagnostics/system_error/what-big.cc (copia de trabajo)
@@ -17,7 +17,6 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <cstring>
#include <string>
#include <system_error>
#include <testsuite_hooks.h>
@@ -30,7 +29,7 @@
bool test __attribute__((unused)) = true;
const std::string xxx(10000, 'x');
test_type t(std::error_code(), xxx);
- VERIFY( std::strcmp(t.what(), xxx.c_str()) == 0 );
+ VERIFY( std::string(t.what()).find(xxx) != std::string::npos );
}
int main(void)
Index: testsuite/19_diagnostics/system_error/what-3.cc
===================================================================
--- testsuite/19_diagnostics/system_error/what-3.cc (revisión: 162786)
+++ testsuite/19_diagnostics/system_error/what-3.cc (copia de trabajo)
@@ -20,7 +20,6 @@
#include <string>
#include <system_error>
-#include <cstring>
#include <testsuite_hooks.h>
// test copy ctors, assignment operators, and persistence of member string data
@@ -52,7 +51,7 @@
obj1 = obj2;
}
allocate_on_stack();
- VERIFY( std::strcmp(strlit1, obj1.what()) == 0 );
+ VERIFY( std::string(obj1.what()).find(strlit1) != std::string::npos );
// block 02
{
@@ -61,7 +60,7 @@
obj1 = obj3;
}
allocate_on_stack();
- VERIFY( std::strcmp(strlit2, obj1.what()) == 0 );
+ VERIFY( std::string(obj1.what()).find(strlit2) != std::string::npos );
}
int main(void)
Index: testsuite/19_diagnostics/system_error/what-4.cc
===================================================================
--- testsuite/19_diagnostics/system_error/what-4.cc (revisión: 162786)
+++ testsuite/19_diagnostics/system_error/what-4.cc (copia de trabajo)
@@ -20,7 +20,6 @@
// 19.1 Exception classes
-#include <cstring>
#include <string>
#include <system_error>
#include <testsuite_hooks.h>
More information about the Libstdc++
mailing list