const char* constructor overloads for stdexcept and system_error.

Ed Smith-Rowland 3dw4rd@verizon.net
Tue Jun 26 00:40:00 GMT 2012


On 06/24/2012 07:25 AM, Jonathan Wakely wrote:
> On 24 June 2012 04:57, Ed Smith-Rowland wrote:
>> Here is a beginning patch to add const char* constructors for the standard
>> exception classes.
>>
>> I didn't bump the so version because I'm not positive how to do it. I tried
>> changing libtool_VERSION in acinclude.m4 and running the autotools commands.
>>   The diffs were very messy because my machine has autotools 1.11.3 rather
>> than 1.11.1.  Also, we might want to wait for something cooler to bump the
>> soname.
> (CC'ing gcc-patches)
>
> Could those new constructors be inline, avoiding the need for a new
> file and version bump?
They certainly could be.  I was just following the style of the existing 
implementation.  The old string ctors were outline.
I'll make the new ctors inline and save some grief.

Built and regtested clean on x86_64-linux-gnu.

For some reason i needed two symbols for

Ed

-------------- next part --------------
Index: include/std/system_error
===================================================================
--- include/std/system_error	(revision 188971)
+++ include/std/system_error	(working copy)
@@ -1,6 +1,7 @@
 // <system_error> -*- C++ -*-
 
-// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
+// 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
@@ -318,17 +319,13 @@
     system_error(error_code __ec, const string& __what)
     : runtime_error(__what + ": " + __ec.message()), _M_code(__ec) { }
 
-    /*
-     * TODO: Add const char* ctors to all exceptions.
-     *
-     * system_error(error_code __ec, const char* __what)
-     * : runtime_error(__what + (": " + __ec.message())), _M_code(__ec) { }
-     *
-     * system_error(int __v, const error_category& __ecat, const char* __what)
-     * : runtime_error(__what + (": " + __ec.message())),
-     *   _M_code(error_code(__v, __ecat)) { }
-     */
+    system_error(error_code __ec, const char* __what)
+    : runtime_error(__what + (": " + __ec.message())), _M_code(__ec) { }
 
+    system_error(int __v, const error_category& __ecat, const char* __what)
+    : runtime_error(__what + (": " + error_code(__v, __ecat).message())),
+      _M_code(__v, __ecat) { }
+
     system_error(int __v, const error_category& __ecat)
     : runtime_error(error_code(__v, __ecat).message()),
       _M_code(__v, __ecat) { }
Index: include/std/stdexcept
===================================================================
--- include/std/stdexcept	(revision 188971)
+++ include/std/stdexcept	(working copy)
@@ -1,6 +1,6 @@
 // Standard exception classes  -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2005, 2007, 2009, 2010, 2011
+// Copyright (C) 2001, 2002, 2005, 2007, 2009, 2010, 2011, 2012
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -59,8 +59,11 @@
 
   public:
     /** Takes a character string describing the error.  */
-    explicit 
-    logic_error(const string& __arg);
+    explicit logic_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    explicit logic_error(const char* __arg)
+    : logic_error(string(__arg)) { }
+#endif
 
     virtual ~logic_error() _GLIBCXX_USE_NOEXCEPT;
 
@@ -76,6 +79,10 @@
   {
   public:
     explicit domain_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    explicit domain_error(const char* __arg)
+    : domain_error(string(__arg)) { }
+#endif
     virtual ~domain_error() _GLIBCXX_USE_NOEXCEPT;
   };
 
@@ -84,6 +91,10 @@
   {
   public:
     explicit invalid_argument(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    explicit invalid_argument(const char* __arg)
+    : invalid_argument(string(__arg)) { }
+#endif
     virtual ~invalid_argument() _GLIBCXX_USE_NOEXCEPT;
   };
 
@@ -93,6 +104,10 @@
   {
   public:
     explicit length_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    explicit length_error(const char* __arg)
+    : length_error(string(__arg)) { }
+#endif
     virtual ~length_error() _GLIBCXX_USE_NOEXCEPT;
   };
 
@@ -102,6 +117,10 @@
   {
   public:
     explicit out_of_range(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    explicit out_of_range(const char* __arg)
+    : out_of_range(string(__arg)) { }
+#endif
     virtual ~out_of_range() _GLIBCXX_USE_NOEXCEPT;
   };
 
@@ -116,8 +135,11 @@
 
   public:
     /** Takes a character string describing the error.  */
-    explicit 
-    runtime_error(const string& __arg);
+    explicit runtime_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    explicit runtime_error(const char* __arg)
+    : runtime_error(string(__arg)) { }
+#endif
 
     virtual ~runtime_error() _GLIBCXX_USE_NOEXCEPT;
 
@@ -132,6 +154,10 @@
   {
   public:
     explicit range_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    explicit range_error(const char* __arg)
+    : range_error(string(__arg)) { }
+#endif
     virtual ~range_error() _GLIBCXX_USE_NOEXCEPT;
   };
 
@@ -140,6 +166,10 @@
   {
   public:
     explicit overflow_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    explicit overflow_error(const char* __arg)
+    : overflow_error(string(__arg)) { }
+#endif
     virtual ~overflow_error() _GLIBCXX_USE_NOEXCEPT;
   };
 
@@ -148,6 +178,10 @@
   {
   public:
     explicit underflow_error(const string& __arg);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    explicit underflow_error(const char* __arg)
+    : underflow_error(string(__arg)) { }
+#endif
     virtual ~underflow_error() _GLIBCXX_USE_NOEXCEPT;
   };
 
Index: config/abi/pre/gnu.ver
===================================================================
--- config/abi/pre/gnu.ver	(revision 188971)
+++ config/abi/pre/gnu.ver	(working copy)
@@ -1319,6 +1319,10 @@
     _ZNSt13__future_base19_Async_state_commonD1Ev;
     _ZNSt13__future_base19_Async_state_commonD2Ev;
 
+    # const char* ctors.
+    _ZNSt11logic_errorC1EPKc;
+    _ZNSt11logic_errorC2EPKc;
+
 } GLIBCXX_3.4.16;
 
 # Symbols in the support library (libsupc++) have their own tag.
@@ -1522,4 +1526,4 @@
   global:
     __cxa_tm_cleanup;
 
-};
\ No newline at end of file
+};
-------------- next part --------------
2012-06-25  Edward Smith-Rowland  <3dw4rd@verizon.net>

	* include/std/system_error (system_error(error_code, const char*),
	system_error(int, const error_category&, const char*)): New.
	* include/std/stdexcept ( logic_error(const char*),
	domain_error(const char*), invalid_argument(const char*),
	length_error(const char*), out_of_range(const char*),
	runtime_error(const char*), range_error(const char*),
	overflow_error(const char*), underflow_error(const char*)): New.
	* config/abi/pre/gnu.ver: Add symbols for logic_error const char* ctors.



More information about the Libstdc++ mailing list