C++11 const char * constructor overloads for exceptions
Benjamin De Kosnik
bkoz@redhat.com
Tue Oct 16 02:54:00 GMT 2012
On Sat, 13 Oct 2012 01:30:22 -0400
Ed Smith-Rowland <3dw4rd@verizon.net> wrote:
> Index: include/std/stdexcept
> ===================================================================
> --- include/std/stdexcept (revision 192405)
> +++ 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: include/std/system_error
> ===================================================================
> --- include/std/system_error (revision 192405)
> +++ 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: config/abi/pre/gnu.ver
> ===================================================================
> --- config/abi/pre/gnu.ver (revision 192405)
> +++ config/abi/pre/gnu.ver (working copy)
> @@ -1338,6 +1338,10 @@
>
> # construction vtable
> _ZTCSt*;
> +
> + # const char* ctors.
> + _ZNSt11logic_errorC1EPKc;
> + _ZNSt11logic_errorC2EPKc;
>
> } GLIBCXX_3.4.17;
>
More information about the Libstdc++
mailing list