* Add const char* constructors for exception classes in <stdexcept>
@ 2013-12-19 0:11 Oleg Endo
2013-12-19 1:19 ` Jonathan Wakely
0 siblings, 1 reply; 11+ messages in thread
From: Oleg Endo @ 2013-12-19 0:11 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 923 bytes --]
Hello,
When writing code such as
...
throw std::logic_error ("cold coffee");
...
currently the construction of std::string happens in the code that
throws the exception, which results in code bloat. Implementing the
const char* constructors as defined by C++11 fixes the issue.
I'm not sure whether the #if __cplusplus >= 201103L checks are required.
C++98 code could also benefit from the overloads.
Tested with 'make all' and 'make install', writing a hello world and
checking the asm output.
Cheers,
Oleg
libstdc++-v3/ChangeLog:
* include/std/stdexcept (logic_error, domain_error,
invalid_argument, length_error, out_of_range, runtime_error,
range_error, overflow_error, underflow_error): Declare const
char* constructors.
* src/c++98/stdexcept.cc (logic_error, domain_error,
invalid_argument, length_error, out_of_range, runtime_error,
range_error, overflow_error, underflow_error): Implement them.
[-- Attachment #2: stdexcept_constchar.patch --]
[-- Type: text/x-patch, Size: 5350 bytes --]
Index: libstdc++-v3/include/std/stdexcept
===================================================================
--- libstdc++-v3/include/std/stdexcept (revision 206101)
+++ libstdc++-v3/include/std/stdexcept (working copy)
@@ -58,9 +58,12 @@
public:
/** Takes a character string describing the error. */
- explicit
+ explicit
logic_error(const string& __arg);
-
+#if __cplusplus >= 201103L
+ explicit
+ logic_error(const char* __arg);
+#endif
virtual ~logic_error() _GLIBCXX_USE_NOEXCEPT;
/** Returns a C-style character string describing the general cause of
@@ -75,6 +78,9 @@
{
public:
explicit domain_error(const string& __arg);
+#if __cplusplus >= 201103L
+ explicit domain_error(const char* __arg);
+#endif
virtual ~domain_error() _GLIBCXX_USE_NOEXCEPT;
};
@@ -83,6 +89,9 @@
{
public:
explicit invalid_argument(const string& __arg);
+#if __cplusplus >= 201103L
+ explicit invalid_argument(const char* __arg);
+#endif
virtual ~invalid_argument() _GLIBCXX_USE_NOEXCEPT;
};
@@ -92,6 +101,9 @@
{
public:
explicit length_error(const string& __arg);
+#if __cplusplus >= 201103L
+ explicit length_error(const char* __arg);
+#endif
virtual ~length_error() _GLIBCXX_USE_NOEXCEPT;
};
@@ -101,6 +113,9 @@
{
public:
explicit out_of_range(const string& __arg);
+#if __cplusplus >= 201103L
+ explicit out_of_range(const char* __arg);
+#endif
virtual ~out_of_range() _GLIBCXX_USE_NOEXCEPT;
};
@@ -115,9 +130,12 @@
public:
/** Takes a character string describing the error. */
- explicit
+ explicit
runtime_error(const string& __arg);
-
+#if __cplusplus >= 201103L
+ explicit
+ runtime_error(const char* __arg);
+#endif
virtual ~runtime_error() _GLIBCXX_USE_NOEXCEPT;
/** Returns a C-style character string describing the general cause of
@@ -131,6 +149,9 @@
{
public:
explicit range_error(const string& __arg);
+#if __cplusplus >= 201103L
+ explicit range_error(const char* __arg);
+#endif
virtual ~range_error() _GLIBCXX_USE_NOEXCEPT;
};
@@ -139,6 +160,9 @@
{
public:
explicit overflow_error(const string& __arg);
+#if __cplusplus >= 201103L
+ explicit overflow_error(const char* __arg);
+#endif
virtual ~overflow_error() _GLIBCXX_USE_NOEXCEPT;
};
@@ -147,6 +171,9 @@
{
public:
explicit underflow_error(const string& __arg);
+#if __cplusplus >= 201103L
+ explicit underflow_error(const char* __arg);
+#endif
virtual ~underflow_error() _GLIBCXX_USE_NOEXCEPT;
};
Index: libstdc++-v3/src/c++98/stdexcept.cc
===================================================================
--- libstdc++-v3/src/c++98/stdexcept.cc (revision 206101)
+++ libstdc++-v3/src/c++98/stdexcept.cc (working copy)
@@ -36,6 +36,11 @@
logic_error::logic_error(const string& __arg)
: exception(), _M_msg(__arg) { }
+#if __cplusplus >= 201103L
+ logic_error::logic_error(const char* __arg)
+ : exception(), _M_msg(__arg) { }
+#endif
+
logic_error::~logic_error() _GLIBCXX_USE_NOEXCEPT { }
const char*
@@ -45,26 +50,51 @@
domain_error::domain_error(const string& __arg)
: logic_error(__arg) { }
+#if __cplusplus >= 201103L
+ domain_error::domain_error(const char* __arg)
+ : logic_error(__arg) { }
+#endif
+
domain_error::~domain_error() _GLIBCXX_USE_NOEXCEPT { }
invalid_argument::invalid_argument(const string& __arg)
: logic_error(__arg) { }
+#if __cplusplus >= 201103L
+ invalid_argument::invalid_argument(const char* __arg)
+ : logic_error(__arg) { }
+#endif
+
invalid_argument::~invalid_argument() _GLIBCXX_USE_NOEXCEPT { }
length_error::length_error(const string& __arg)
: logic_error(__arg) { }
+#if __cplusplus >= 201103L
+ length_error::length_error(const char* __arg)
+ : logic_error(__arg) { }
+#endif
+
length_error::~length_error() _GLIBCXX_USE_NOEXCEPT { }
out_of_range::out_of_range(const string& __arg)
: logic_error(__arg) { }
+#if __cplusplus >= 201103L
+ out_of_range::out_of_range(const char* __arg)
+ : logic_error(__arg) { }
+#endif
+
out_of_range::~out_of_range() _GLIBCXX_USE_NOEXCEPT { }
runtime_error::runtime_error(const string& __arg)
: exception(), _M_msg(__arg) { }
+#if __cplusplus >= 201103L
+ runtime_error::runtime_error(const char* __arg)
+ : exception(), _M_msg(__arg) { }
+#endif
+
runtime_error::~runtime_error() _GLIBCXX_USE_NOEXCEPT { }
const char*
@@ -74,16 +104,31 @@
range_error::range_error(const string& __arg)
: runtime_error(__arg) { }
+#if __cplusplus >= 201103L
+ range_error::range_error(const char* __arg)
+ : runtime_error(__arg) { }
+#endif
+
range_error::~range_error() _GLIBCXX_USE_NOEXCEPT { }
overflow_error::overflow_error(const string& __arg)
: runtime_error(__arg) { }
+#if __cplusplus >= 201103L
+ overflow_error:overflow_error(const char* __arg)
+ : runtime_error(__arg) { }
+#endif
+
overflow_error::~overflow_error() _GLIBCXX_USE_NOEXCEPT { }
underflow_error::underflow_error(const string& __arg)
: runtime_error(__arg) { }
+#if __cplusplus >= 201103L
+ underflow_error::underflow_error(const char* __arg)
+ : runtime_error(__arg) { }
+#endif
+
underflow_error::~underflow_error() _GLIBCXX_USE_NOEXCEPT { }
_GLIBCXX_END_NAMESPACE_VERSION
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Add const char* constructors for exception classes in <stdexcept>
2013-12-19 0:11 Add const char* constructors for exception classes in <stdexcept> Oleg Endo
@ 2013-12-19 1:19 ` Jonathan Wakely
2013-12-19 15:28 ` Oleg Endo
0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Wakely @ 2013-12-19 1:19 UTC (permalink / raw)
To: Oleg Endo; +Cc: libstdc++, gcc-patches
On 19 December 2013 00:10, Oleg Endo wrote:
> Hello,
>
> When writing code such as
> ...
> throw std::logic_error ("cold coffee");
> ...
> currently the construction of std::string happens in the code that
> throws the exception, which results in code bloat. Implementing the
> const char* constructors as defined by C++11 fixes the issue.
> I'm not sure whether the #if __cplusplus >= 201103L checks are required.
> C++98 code could also benefit from the overloads.
I think there was some good reason we haven't added these yet, but I
can't remember it.
> Tested with 'make all' and 'make install', writing a hello world and
> checking the asm output.
For all patches we need to know that the libstdc++ testsuite passes too.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Add const char* constructors for exception classes in <stdexcept>
2013-12-19 1:19 ` Jonathan Wakely
@ 2013-12-19 15:28 ` Oleg Endo
2014-01-26 14:15 ` [PING] " Oleg Endo
0 siblings, 1 reply; 11+ messages in thread
From: Oleg Endo @ 2013-12-19 15:28 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 2410 bytes --]
On Thu, 2013-12-19 at 01:19 +0000, Jonathan Wakely wrote:
> On 19 December 2013 00:10, Oleg Endo wrote:
> > Hello,
> >
> > When writing code such as
> > ...
> > throw std::logic_error ("cold coffee");
> > ...
> > currently the construction of std::string happens in the code that
> > throws the exception, which results in code bloat. Implementing the
> > const char* constructors as defined by C++11 fixes the issue.
> > I'm not sure whether the #if __cplusplus >= 201103L checks are required.
> > C++98 code could also benefit from the overloads.
>
> I think there was some good reason we haven't added these yet, but I
> can't remember it.
>
> > Tested with 'make all' and 'make install', writing a hello world and
> > checking the asm output.
>
> For all patches we need to know that the libstdc++ testsuite passes too.
Right, I should have done that in the first place. The patch was
broken. Sorry for the noise.
Files in libstdc++-v3/src/c++98/ seem to be never compiled with C++11.
Thus I can think of two options:
1) Add const char* ctors for C++98 and C++11.
2) Add #ifdef'ed declarations to libstdc++-v3/include/std/stdexcept and
add a new file libstdc++-v3/src/c++11/stdexcept.cc with the
implementations.
The attached patch does 1).
Tested with 'make all' and 'make check-target-libstdc++-v3' on
i686-pc-linux-gnu, configured with:
../gcc-trunk2/configure --prefix=/<...> --enable-languages=c,c++
=== libstdc++ Summary ===
# of expected passes 5142
# of unexpected failures 2
# of expected failures 34
# of unsupported tests 476
Cheers,
Oleg
libstdc++-v3/ChangeLog:
* include/std/stdexcept (logic_error, domain_error,
invalid_argument, length_error, out_of_range, runtime_error,
range_error, overflow_error, underflow_error): Declare const
char* constructors.
* src/c++98/stdexcept.cc (logic_error, domain_error,
invalid_argument, length_error, out_of_range, runtime_error,
range_error, overflow_error, underflow_error): Implement them.
* config/abi/pre/gnu.ver ( _ZNSt11logic_errorC[12]EPKc,
_ZNSt12domain_errorC[12]EPKc, _ZNSt16invalid_argumentC[12]EPKc,
_ZNSt12length_errorC[12]EPKc, _ZNSt12out_of_rangeC[12]EPKc,
_ZNSt13runtime_errorC[12]EPKc, _ZNSt11range_errorC[12]EPKc,
_ZNSt14overflow_errorC[12]EPKc, _ZNSt15underflow_errorC[12]EPKc):
Add new exports.
* doc/xml/manual/status_cxx2011.xml: Update.
[-- Attachment #2: stdexcept_constchar2.patch --]
[-- Type: text/x-patch, Size: 6625 bytes --]
Index: libstdc++-v3/config/abi/pre/gnu.ver
===================================================================
--- libstdc++-v3/config/abi/pre/gnu.ver (revision 206101)
+++ libstdc++-v3/config/abi/pre/gnu.ver (working copy)
@@ -1371,6 +1371,33 @@
# std::regex_error::regex_error(std::regex_constants::error_type)
_ZNSt11regex_errorC[01]ENSt15regex_constants10error_typeE;
+ # std::logic_error::logic_error(const char*)
+ _ZNSt11logic_errorC[12]EPKc;
+
+ # std::domain_error::domain_error(const char*)
+ _ZNSt12domain_errorC[12]EPKc;
+
+ # std::invalid_argument::invalid_argument(const char*)
+ _ZNSt16invalid_argumentC[12]EPKc;
+
+ # std::length_error::length_error(const char*)
+ _ZNSt12length_errorC[12]EPKc;
+
+ # std::out_of_range::out_of_range(const char*)
+ _ZNSt12out_of_rangeC[12]EPKc;
+
+ # std::runtime_error::runtime_error(const char*)
+ _ZNSt13runtime_errorC[12]EPKc;
+
+ # std::range_error::range_error(const char*)
+ _ZNSt11range_errorC[12]EPKc;
+
+ # std::overflow_error::overflow_error(const char*)
+ _ZNSt14overflow_errorC[12]EPKc;
+
+ # std::underflow_error::underflow_error(const char*)
+ _ZNSt15underflow_errorC[12]EPKc;
+
} GLIBCXX_3.4.19;
# Symbols in the support library (libsupc++) have their own tag.
Index: libstdc++-v3/src/c++98/stdexcept.cc
===================================================================
--- libstdc++-v3/src/c++98/stdexcept.cc (revision 206101)
+++ libstdc++-v3/src/c++98/stdexcept.cc (working copy)
@@ -36,6 +36,9 @@
logic_error::logic_error(const string& __arg)
: exception(), _M_msg(__arg) { }
+ logic_error::logic_error(const char* __arg)
+ : exception(), _M_msg(__arg) { }
+
logic_error::~logic_error() _GLIBCXX_USE_NOEXCEPT { }
const char*
@@ -45,26 +48,41 @@
domain_error::domain_error(const string& __arg)
: logic_error(__arg) { }
+ domain_error::domain_error(const char* __arg)
+ : logic_error(__arg) { }
+
domain_error::~domain_error() _GLIBCXX_USE_NOEXCEPT { }
invalid_argument::invalid_argument(const string& __arg)
: logic_error(__arg) { }
+ invalid_argument::invalid_argument(const char* __arg)
+ : logic_error(__arg) { }
+
invalid_argument::~invalid_argument() _GLIBCXX_USE_NOEXCEPT { }
length_error::length_error(const string& __arg)
: logic_error(__arg) { }
+ length_error::length_error(const char* __arg)
+ : logic_error(__arg) { }
+
length_error::~length_error() _GLIBCXX_USE_NOEXCEPT { }
out_of_range::out_of_range(const string& __arg)
: logic_error(__arg) { }
+ out_of_range::out_of_range(const char* __arg)
+ : logic_error(__arg) { }
+
out_of_range::~out_of_range() _GLIBCXX_USE_NOEXCEPT { }
runtime_error::runtime_error(const string& __arg)
: exception(), _M_msg(__arg) { }
+ runtime_error::runtime_error(const char* __arg)
+ : exception(), _M_msg(__arg) { }
+
runtime_error::~runtime_error() _GLIBCXX_USE_NOEXCEPT { }
const char*
@@ -74,16 +92,25 @@
range_error::range_error(const string& __arg)
: runtime_error(__arg) { }
+ range_error::range_error(const char* __arg)
+ : runtime_error(__arg) { }
+
range_error::~range_error() _GLIBCXX_USE_NOEXCEPT { }
overflow_error::overflow_error(const string& __arg)
: runtime_error(__arg) { }
+ overflow_error::overflow_error(const char* __arg)
+ : runtime_error(__arg) { }
+
overflow_error::~overflow_error() _GLIBCXX_USE_NOEXCEPT { }
underflow_error::underflow_error(const string& __arg)
: runtime_error(__arg) { }
+ underflow_error::underflow_error(const char* __arg)
+ : runtime_error(__arg) { }
+
underflow_error::~underflow_error() _GLIBCXX_USE_NOEXCEPT { }
_GLIBCXX_END_NAMESPACE_VERSION
Index: libstdc++-v3/doc/xml/manual/status_cxx2011.xml
===================================================================
--- libstdc++-v3/doc/xml/manual/status_cxx2011.xml (revision 206101)
+++ libstdc++-v3/doc/xml/manual/status_cxx2011.xml (working copy)
@@ -270,11 +270,10 @@
<entry/>
</row>
<row>
- <?dbhtml bgcolor="#B0B0B0" ?>
<entry>19.2</entry>
<entry>Exception classes</entry>
- <entry>Partial</entry>
- <entry>Missing <code>const char*</code> constructors.</entry>
+ <entry>Y</entry>
+ <entry/>
</row>
<row>
<entry>19.3</entry>
Index: libstdc++-v3/include/std/stdexcept
===================================================================
--- libstdc++-v3/include/std/stdexcept (revision 206101)
+++ libstdc++-v3/include/std/stdexcept (working copy)
@@ -58,9 +58,12 @@
public:
/** Takes a character string describing the error. */
- explicit
+ explicit
logic_error(const string& __arg);
+ explicit
+ logic_error(const char* __arg);
+
virtual ~logic_error() _GLIBCXX_USE_NOEXCEPT;
/** Returns a C-style character string describing the general cause of
@@ -75,6 +78,8 @@
{
public:
explicit domain_error(const string& __arg);
+ explicit domain_error(const char* __arg);
+
virtual ~domain_error() _GLIBCXX_USE_NOEXCEPT;
};
@@ -83,6 +88,8 @@
{
public:
explicit invalid_argument(const string& __arg);
+ explicit invalid_argument(const char* __arg);
+
virtual ~invalid_argument() _GLIBCXX_USE_NOEXCEPT;
};
@@ -92,6 +99,8 @@
{
public:
explicit length_error(const string& __arg);
+ explicit length_error(const char* __arg);
+
virtual ~length_error() _GLIBCXX_USE_NOEXCEPT;
};
@@ -101,6 +110,8 @@
{
public:
explicit out_of_range(const string& __arg);
+ explicit out_of_range(const char* __arg);
+
virtual ~out_of_range() _GLIBCXX_USE_NOEXCEPT;
};
@@ -115,9 +126,12 @@
public:
/** Takes a character string describing the error. */
- explicit
+ explicit
runtime_error(const string& __arg);
+ explicit
+ runtime_error(const char* __arg);
+
virtual ~runtime_error() _GLIBCXX_USE_NOEXCEPT;
/** Returns a C-style character string describing the general cause of
@@ -131,6 +145,8 @@
{
public:
explicit range_error(const string& __arg);
+ explicit range_error(const char* __arg);
+
virtual ~range_error() _GLIBCXX_USE_NOEXCEPT;
};
@@ -139,6 +155,8 @@
{
public:
explicit overflow_error(const string& __arg);
+ explicit overflow_error(const char* __arg);
+
virtual ~overflow_error() _GLIBCXX_USE_NOEXCEPT;
};
@@ -147,6 +165,8 @@
{
public:
explicit underflow_error(const string& __arg);
+ explicit underflow_error(const char* __arg);
+
virtual ~underflow_error() _GLIBCXX_USE_NOEXCEPT;
};
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PING] Re: Add const char* constructors for exception classes in <stdexcept>
2013-12-19 15:28 ` Oleg Endo
@ 2014-01-26 14:15 ` Oleg Endo
2014-01-29 15:21 ` Jonathan Wakely
0 siblings, 1 reply; 11+ messages in thread
From: Oleg Endo @ 2014-01-26 14:15 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches
Ping.
The patch in question is here:
http://gcc.gnu.org/ml/gcc-patches/2013-12/msg01688.html
On Thu, 2013-12-19 at 16:28 +0100, Oleg Endo wrote:
> On Thu, 2013-12-19 at 01:19 +0000, Jonathan Wakely wrote:
> > On 19 December 2013 00:10, Oleg Endo wrote:
> > > Hello,
> > >
> > > When writing code such as
> > > ...
> > > throw std::logic_error ("cold coffee");
> > > ...
> > > currently the construction of std::string happens in the code that
> > > throws the exception, which results in code bloat. Implementing the
> > > const char* constructors as defined by C++11 fixes the issue.
> > > I'm not sure whether the #if __cplusplus >= 201103L checks are required.
> > > C++98 code could also benefit from the overloads.
> >
> > I think there was some good reason we haven't added these yet, but I
> > can't remember it.
> >
> > > Tested with 'make all' and 'make install', writing a hello world and
> > > checking the asm output.
> >
> > For all patches we need to know that the libstdc++ testsuite passes too.
>
> Right, I should have done that in the first place. The patch was
> broken. Sorry for the noise.
>
> Files in libstdc++-v3/src/c++98/ seem to be never compiled with C++11.
> Thus I can think of two options:
> 1) Add const char* ctors for C++98 and C++11.
> 2) Add #ifdef'ed declarations to libstdc++-v3/include/std/stdexcept and
> add a new file libstdc++-v3/src/c++11/stdexcept.cc with the
> implementations.
>
> The attached patch does 1).
>
> Tested with 'make all' and 'make check-target-libstdc++-v3' on
> i686-pc-linux-gnu, configured with:
> ../gcc-trunk2/configure --prefix=/<...> --enable-languages=c,c++
>
> === libstdc++ Summary ===
>
> # of expected passes 5142
> # of unexpected failures 2
> # of expected failures 34
> # of unsupported tests 476
>
> Cheers,
> Oleg
>
> libstdc++-v3/ChangeLog:
> * include/std/stdexcept (logic_error, domain_error,
> invalid_argument, length_error, out_of_range, runtime_error,
> range_error, overflow_error, underflow_error): Declare const
> char* constructors.
> * src/c++98/stdexcept.cc (logic_error, domain_error,
> invalid_argument, length_error, out_of_range, runtime_error,
> range_error, overflow_error, underflow_error): Implement them.
> * config/abi/pre/gnu.ver ( _ZNSt11logic_errorC[12]EPKc,
> _ZNSt12domain_errorC[12]EPKc, _ZNSt16invalid_argumentC[12]EPKc,
> _ZNSt12length_errorC[12]EPKc, _ZNSt12out_of_rangeC[12]EPKc,
> _ZNSt13runtime_errorC[12]EPKc, _ZNSt11range_errorC[12]EPKc,
> _ZNSt14overflow_errorC[12]EPKc, _ZNSt15underflow_errorC[12]EPKc):
> Add new exports.
> * doc/xml/manual/status_cxx2011.xml: Update.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PING] Re: Add const char* constructors for exception classes in <stdexcept>
2014-01-26 14:15 ` [PING] " Oleg Endo
@ 2014-01-29 15:21 ` Jonathan Wakely
2014-01-29 21:17 ` Oleg Endo
0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Wakely @ 2014-01-29 15:21 UTC (permalink / raw)
To: Oleg Endo; +Cc: libstdc++, gcc-patches
On 26/01/14 15:15 +0100, Oleg Endo wrote:
>> Files in libstdc++-v3/src/c++98/ seem to be never compiled with C++11.
>> Thus I can think of two options:
>> 1) Add const char* ctors for C++98 and C++11.
>> 2) Add #ifdef'ed declarations to libstdc++-v3/include/std/stdexcept and
>> add a new file libstdc++-v3/src/c++11/stdexcept.cc with the
>> implementations.
3) Move stdexcept.cc from src/c++98 to src/c++11
4) Define the functions inline using forwarding constructors, which
means we don't need new exports.
>> The attached patch does 1).
I don't think we want the constructors in C++03 mode though, it could
break some valid programs e.g. a custom string type with implicit
conversion to const char* and std::string can be passed to an exception
constructor in C++03, but adding the overloads would make it
ambiguous.
I think I prefer option 4, it avoids adding new exports during Stage 3
(although the patch was initially posted during Stage 1, it is now
quite late to add new exports, which is not your fault but still a
concern.)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PING] Re: Add const char* constructors for exception classes in <stdexcept>
2014-01-29 15:21 ` Jonathan Wakely
@ 2014-01-29 21:17 ` Oleg Endo
2014-01-29 21:38 ` Jonathan Wakely
0 siblings, 1 reply; 11+ messages in thread
From: Oleg Endo @ 2014-01-29 21:17 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches
On Wed, 2014-01-29 at 15:21 +0000, Jonathan Wakely wrote:
> On 26/01/14 15:15 +0100, Oleg Endo wrote:
> >> Files in libstdc++-v3/src/c++98/ seem to be never compiled with C++11.
> >> Thus I can think of two options:
> >> 1) Add const char* ctors for C++98 and C++11.
> >> 2) Add #ifdef'ed declarations to libstdc++-v3/include/std/stdexcept and
> >> add a new file libstdc++-v3/src/c++11/stdexcept.cc with the
> >> implementations.
>
> 3) Move stdexcept.cc from src/c++98 to src/c++11
> 4) Define the functions inline using forwarding constructors, which
> means we don't need new exports.
>
> >> The attached patch does 1).
>
> I don't think we want the constructors in C++03 mode though, it could
> break some valid programs e.g. a custom string type with implicit
> conversion to const char* and std::string can be passed to an exception
> constructor in C++03, but adding the overloads would make it
> ambiguous.
Good point.
>
> I think I prefer option 4, it avoids adding new exports during Stage 3
> (although the patch was initially posted during Stage 1, it is now
> quite late to add new exports, which is not your fault but still a
> concern.)
My original intention was to eliminate code bloat when doing something
like throw std::logic_error ("cold coffee");
If the const char* overloads are inlined it will emit code to construct
an std::string from const char* in user code where the exception is
being constructed over and over again. The idea was to move that code
into the std library.
BTW the original patch was posted during Stage 3 (19.12.2013). I don't
mind waiting until Stage 1 if adding exports now is a problem.
Cheers,
Oleg
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PING] Re: Add const char* constructors for exception classes in <stdexcept>
2014-01-29 21:17 ` Oleg Endo
@ 2014-01-29 21:38 ` Jonathan Wakely
2014-01-29 22:45 ` Oleg Endo
0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Wakely @ 2014-01-29 21:38 UTC (permalink / raw)
To: Oleg Endo; +Cc: Jonathan Wakely, libstdc++, gcc-patches
On 29 January 2014 21:17, Oleg Endo wrote:
> My original intention was to eliminate code bloat when doing something
> like throw std::logic_error ("cold coffee");
> If the const char* overloads are inlined it will emit code to construct
> an std::string from const char* in user code where the exception is
> being constructed over and over again. The idea was to move that code
> into the std library.
That's exactly what happens today with the constructors that only take
a std::string, so it wouldn't be any worse than what we have now,
would it?
> BTW the original patch was posted during Stage 3 (19.12.2013). I don't
> mind waiting until Stage 1 if adding exports now is a problem.
OK, let's wait and decide how we want to do it properly in stage 1.
(If we're going to make various changes that impact the ABI during the
next stage 1 we might even want to consider changing the
std::exception base class to store something like a
std::shared_ptr<std::string> so that copying an exception object will
never throw an exception, which is something I've been thinking about
recently.)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PING] Re: Add const char* constructors for exception classes in <stdexcept>
2014-01-29 21:38 ` Jonathan Wakely
@ 2014-01-29 22:45 ` Oleg Endo
2014-05-01 16:18 ` Oleg Endo
0 siblings, 1 reply; 11+ messages in thread
From: Oleg Endo @ 2014-01-29 22:45 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 2353 bytes --]
On Wed, 2014-01-29 at 21:38 +0000, Jonathan Wakely wrote:
> On 29 January 2014 21:17, Oleg Endo wrote:
> > My original intention was to eliminate code bloat when doing something
> > like throw std::logic_error ("cold coffee");
> > If the const char* overloads are inlined it will emit code to construct
> > an std::string from const char* in user code where the exception is
> > being constructed over and over again. The idea was to move that code
> > into the std library.
>
> That's exactly what happens today with the constructors that only take
> a std::string, so it wouldn't be any worse than what we have now,
> would it?
Sorry, I'm not sure I understand your question. Maybe you meant "any
better than what we have"? Anyway, I've attached two outputs that show
what I mean. The version with the const char* ctor overloads
implemented in the library is significantly shorter in the throwing path
(5x function call vs. 7x function call + other inlined std::string ctor
code).
>
> > BTW the original patch was posted during Stage 3 (19.12.2013). I don't
> > mind waiting until Stage 1 if adding exports now is a problem.
>
> OK, let's wait and decide how we want to do it properly in stage 1.
Sure. Actually I've missed some of the other exception types in
system_error, which should be added, too. That would eliminate the
TODO: Add const char* ctors to all exceptions.
I'd also propose moving the system_error ctor implementations into the
library as well, for the same reasons as above.
>
> (If we're going to make various changes that impact the ABI during the
> next stage 1 we might even want to consider changing the
> std::exception base class to store something like a
> std::shared_ptr<std::string> so that copying an exception object will
> never throw an exception, which is something I've been thinking about
> recently.)
Wouldn't using std::shared_ptr<std::string> introduce an additional heap
allocation when creating the exception, though?
How about storing the exception message in a plain zero terminated
string instead? This would require only one heap allocation if the
string data is prefixed with a refcount variable. Basically,
std::make_shared re-invented because it doesn't work with arrays.
Or maybe implement N3640 + N3641 first (even if for library internal use
only as a start)...
Cheers,
Oleg
[-- Attachment #2: no_const_char_overloads.s --]
[-- Type: text/x-tex, Size: 5223 bytes --]
.file "sh_tmp.cpp"
.text
.little
.section .rodata.str1.4,"aMS",@progbits,1
.align 2
.LC0:
.string "multiplication by zero"
.text
.align 1
.align 2
.global __Z6test03ii
.type __Z6test03ii, @function
__Z6test03ii:
.LFB746:
.cfi_startproc
.cfi_personality 0,___gxx_personality_v0
.cfi_lsda 0xb,.LLSDA746
mov.l r8,@-r15 ! 183 movsi_ie/9 [length = 2]
.cfi_def_cfa_offset 4
.cfi_offset 8, -4
mov.l r9,@-r15 ! 184 movsi_ie/9 [length = 2]
.cfi_def_cfa_offset 8
.cfi_offset 9, -8
sts.l pr,@-r15 ! 185 movsi_ie/11 [length = 2]
.cfi_def_cfa_offset 12
.cfi_offset 17, -12
add #-8,r15 ! 186 *addsi3_compact [length = 2]
.cfi_def_cfa_offset 20
tst r5,r5 ! 7 cmpeqsi_t/1 [length = 2]
bt/s .L19 ! 8 *cbranch_t [length = 2]
mul.l r5,r4 ! 68 mul_l [length = 2]
sts macl,r0 ! 116 movsi_ie/7 [length = 2]
add #8,r15 ! 191 *addsi3_compact [length = 2]
.cfi_remember_state
.cfi_def_cfa_offset 12
lds.l @r15+,pr ! 193 movsi_ie/15 [length = 2]
.cfi_restore 17
.cfi_def_cfa_offset 8
mov.l @r15+,r9 ! 194 movsi_ie/6 [length = 2]
.cfi_restore 9
.cfi_def_cfa_offset 4
rts ! 197 *return_i [length = 2]
mov.l @r15+,r8 ! 195 movsi_ie/6 [length = 2]
.cfi_def_cfa_offset 0
.cfi_restore 8
.align 1
.L19:
.cfi_restore_state
mov.l .L21,r0 ! 171 movsi_ie/1 [length = 2]
jsr @r0 ! 12 call_valuei [length = 2]
mov #8,r4 ! 11 movsi_ie/3 [length = 2]
mov.l .L22,r1 ! 170 movsi_ie/1 [length = 2]
mov r15,r4 ! 174 movsi_ie/2 [length = 2]
mov r15,r6 ! 175 movsi_ie/2 [length = 2]
mov r0,r9 ! 13 movsi_ie/2 [length = 2]
add #4,r4 ! 19 *addsi3_compact [length = 2]
mov.l .L23,r5 ! 20 movsi_ie/1 [length = 2]
.LEHB0:
jsr @r1 ! 22 calli [length = 2]
add #2,r6 ! 21 *addsi3_compact [length = 2]
.LEHE0:
mov.l .L24,r1 ! 169 movsi_ie/1 [length = 2]
mov r15,r5 ! 176 movsi_ie/2 [length = 2]
mov r9,r4 ! 26 movsi_ie/2 [length = 2]
.LEHB1:
jsr @r1 ! 28 calli [length = 2]
add #4,r5 ! 27 *addsi3_compact [length = 2]
.LEHE1:
mov.l @(4,r15),r1 ! 32 movsi_ie/6 [length = 2]
mov.l .L33,r2 ! 34 movsi_ie/1 [length = 2]
mov r1,r4 ! 177 movsi_ie/2 [length = 2]
add #-12,r4 ! 33 *addsi3_compact [length = 2]
cmp/eq r2,r4 ! 35 cmpeqsi_t/3 [length = 2]
bf/s .L20 ! 36 *cbranch_t [length = 2]
add #-64,r1 ! 42 *addsi3_compact [length = 2]
.L4:
mov.l .L26,r1 ! 167 movsi_ie/1 [length = 2]
mov.l .L27,r5 ! 62 movsi_ie/1 [length = 2]
mov.l .L28,r6 ! 63 movsi_ie/1 [length = 2]
.LEHB2:
jsr @r1 ! 64 calli [length = 2]
mov r9,r4 ! 61 movsi_ie/2 [length = 2]
.align 1
.L11:
mov r4,r8 ! 123 movsi_ie/2 [length = 2]
.L17:
mov.l .L34,r1 ! 147 movsi_ie/1 [length = 2]
lds.l @r1+,fpscr ! 207 fpu_switch/2 [length = 2]
.L10:
mov.l .L30,r1 ! 165 movsi_ie/1 [length = 2]
jsr @r1 ! 109 calli [length = 2]
mov r9,r4 ! 108 movsi_ie/2 [length = 2]
mov.l .L31,r1 ! 164 movsi_ie/1 [length = 2]
jsr @r1 ! 113 calli [length = 2]
mov r8,r4 ! 112 movsi_ie/2 [length = 2]
.LEHE2:
.align 1
.L20:
mov.l @(60,r1),r2 ! 43 movsi_ie/6 [length = 2]
mov r2,r3 ! 178 movsi_ie/2 [length = 2]
add #-1,r3 ! 45 *addsi3_compact [length = 2]
cmp/pl r2 ! 48 cmpgtsi_t/1 [length = 2]
bt/s .L4 ! 49 *cbranch_t [length = 2]
mov.l r3,@(60,r1) ! 46 movsi_ie/9 [length = 2]
mov.l .L35,r1 ! 168 movsi_ie/1 [length = 2]
mov r15,r5 ! 179 movsi_ie/2 [length = 2]
jsr @r1 ! 55 calli [length = 2]
add #3,r5 ! 54 *addsi3_compact [length = 2]
bra .L4
nop ! 215 jump_compact [length = 4]
.align 1
.L12:
mov.l @(4,r15),r1 ! 77 movsi_ie/6 [length = 2]
mov r4,r8 ! 129 movsi_ie/2 [length = 2]
mov.l .L33,r2 ! 79 movsi_ie/1 [length = 2]
mov r1,r4 ! 180 movsi_ie/2 [length = 2]
add #-12,r4 ! 78 *addsi3_compact [length = 2]
cmp/eq r2,r4 ! 80 cmpeqsi_t/3 [length = 2]
bt .L17 ! 81 *cbranch_t [length = 2]
add #-64,r1 ! 87 *addsi3_compact [length = 2]
mov.l @(60,r1),r2 ! 88 movsi_ie/6 [length = 2]
mov r2,r3 ! 181 movsi_ie/2 [length = 2]
add #-1,r3 ! 90 *addsi3_compact [length = 2]
cmp/pl r2 ! 93 cmpgtsi_t/1 [length = 2]
bt/s .L17 ! 94 *cbranch_t [length = 2]
mov.l r3,@(60,r1) ! 91 movsi_ie/9 [length = 2]
mov.l .L34,r1 ! 153 movsi_ie/1 [length = 2]
mov r15,r5 ! 182 movsi_ie/2 [length = 2]
lds.l @r1+,fpscr ! 208 fpu_switch/2 [length = 2]
mov.l .L35,r1 ! 166 movsi_ie/1 [length = 2]
jsr @r1 ! 100 calli [length = 2]
add #3,r5 ! 99 *addsi3_compact [length = 2]
bra .L10
nop ! 217 jump_compact [length = 4]
.L36:
.align 2
.L21:
.long ___cxa_allocate_exception
.L22:
.long __ZNSsC1EPKcRKSaIcE
.L23:
.long .LC0
.L24:
.long __ZNSt11logic_errorC1ERKSs
.L33:
.long __ZNSs4_Rep20_S_empty_rep_storageE
.L26:
.long ___cxa_throw
.L27:
.long __ZTISt11logic_error
.L28:
.long __ZNSt11logic_errorD1Ev
.L34:
.long ___fpscr_values+4
.L30:
.long ___cxa_free_exception
.L31:
.long __Unwind_Resume
.L35:
.long __ZNSs4_Rep10_M_destroyERKSaIcE
.cfi_endproc
.LFE746:
.global ___gxx_personality_v0
.section .gcc_except_table,"a",@progbits
.LLSDA746:
.byte 0xff
.byte 0xff
.byte 0x1
.uleb128 .LLSDACSE746-.LLSDACSB746
.LLSDACSB746:
.uleb128 .LEHB0-.LFB746
.uleb128 .LEHE0-.LEHB0
.uleb128 .L11-.LFB746
.uleb128 0
.uleb128 .LEHB1-.LFB746
.uleb128 .LEHE1-.LEHB1
.uleb128 .L12-.LFB746
.uleb128 0
.uleb128 .LEHB2-.LFB746
.uleb128 .LEHE2-.LEHB2
.uleb128 0
.uleb128 0
.LLSDACSE746:
.text
.size __Z6test03ii, .-__Z6test03ii
[-- Attachment #3: const_char_overloads.s --]
[-- Type: text/x-tex, Size: 2446 bytes --]
.file "sh_tmp.cpp"
.text
.little
.section .rodata.str1.4,"aMS",@progbits,1
.align 2
.LC0:
.string "multiplication by zero"
.text
.align 1
.align 2
.global __Z6test03ii
.type __Z6test03ii, @function
__Z6test03ii:
.LFB746:
.cfi_startproc
.cfi_personality 0,___gxx_personality_v0
.cfi_lsda 0xb,.LLSDA746
tst r5,r5 ! 7 cmpeqsi_t/1 [length = 2]
bt/s .L9 ! 8 *cbranch_t [length = 2]
mul.l r5,r4 ! 31 mul_l [length = 2]
rts ! 81 *simple_return_i [length = 2]
sts macl,r0 ! 47 movsi_ie/7 [length = 2]
.align 1
.L9:
mov.l r8,@-r15 ! 73 movsi_ie/9 [length = 2]
.cfi_def_cfa_offset 4
.cfi_offset 8, -4
mov.l r9,@-r15 ! 74 movsi_ie/9 [length = 2]
.cfi_def_cfa_offset 8
.cfi_offset 9, -8
sts.l pr,@-r15 ! 75 movsi_ie/11 [length = 2]
.cfi_def_cfa_offset 12
.cfi_offset 17, -12
mov.l .L10,r0 ! 71 movsi_ie/1 [length = 2]
jsr @r0 ! 12 call_valuei [length = 2]
mov #8,r4 ! 11 movsi_ie/3 [length = 2]
mov.l .L11,r1 ! 70 movsi_ie/1 [length = 2]
mov r0,r8 ! 13 movsi_ie/2 [length = 2]
mov.l .L12,r5 ! 18 movsi_ie/1 [length = 2]
.LEHB0:
jsr @r1 ! 19 calli [length = 2]
mov r0,r4 ! 17 movsi_ie/2 [length = 2]
.LEHE0:
mov.l .L13,r1 ! 69 movsi_ie/1 [length = 2]
mov.l .L14,r5 ! 25 movsi_ie/1 [length = 2]
mov.l .L15,r6 ! 26 movsi_ie/1 [length = 2]
.LEHB1:
jsr @r1 ! 27 calli [length = 2]
mov r8,r4 ! 24 movsi_ie/2 [length = 2]
.align 1
.L4:
mov.l .L16,r1 ! 64 movsi_ie/1 [length = 2]
mov r4,r9 ! 54 movsi_ie/2 [length = 2]
lds.l @r1+,fpscr ! 82 fpu_switch/2 [length = 2]
mov.l .L17,r1 ! 68 movsi_ie/1 [length = 2]
jsr @r1 ! 40 calli [length = 2]
mov r8,r4 ! 39 movsi_ie/2 [length = 2]
mov.l .L18,r1 ! 67 movsi_ie/1 [length = 2]
jsr @r1 ! 44 calli [length = 2]
mov r9,r4 ! 43 movsi_ie/2 [length = 2]
.LEHE1:
.L19:
.align 2
.L10:
.long ___cxa_allocate_exception
.L11:
.long __ZNSt11logic_errorC1EPKc
.L12:
.long .LC0
.L13:
.long ___cxa_throw
.L14:
.long __ZTISt11logic_error
.L15:
.long __ZNSt11logic_errorD1Ev
.L16:
.long ___fpscr_values+4
.L17:
.long ___cxa_free_exception
.L18:
.long __Unwind_Resume
.cfi_endproc
.LFE746:
.global ___gxx_personality_v0
.section .gcc_except_table,"a",@progbits
.LLSDA746:
.byte 0xff
.byte 0xff
.byte 0x1
.uleb128 .LLSDACSE746-.LLSDACSB746
.LLSDACSB746:
.uleb128 .LEHB0-.LFB746
.uleb128 .LEHE0-.LEHB0
.uleb128 .L4-.LFB746
.uleb128 0
.uleb128 .LEHB1-.LFB746
.uleb128 .LEHE1-.LEHB1
.uleb128 0
.uleb128 0
.LLSDACSE746:
.text
.size __Z6test03ii, .-__Z6test03ii
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PING] Re: Add const char* constructors for exception classes in <stdexcept>
2014-01-29 22:45 ` Oleg Endo
@ 2014-05-01 16:18 ` Oleg Endo
2014-05-02 15:57 ` Jonathan Wakely
0 siblings, 1 reply; 11+ messages in thread
From: Oleg Endo @ 2014-05-01 16:18 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches
Jonathan,
now that we're in stage 1 again, I'd like to revive the issue below. Do
you have any particular plans? How should we proceed?
Cheers,
Oleg
On Wed, 2014-01-29 at 23:45 +0100, Oleg Endo wrote:
> On Wed, 2014-01-29 at 21:38 +0000, Jonathan Wakely wrote:
> > On 29 January 2014 21:17, Oleg Endo wrote:
> > > My original intention was to eliminate code bloat when doing something
> > > like throw std::logic_error ("cold coffee");
> > > If the const char* overloads are inlined it will emit code to construct
> > > an std::string from const char* in user code where the exception is
> > > being constructed over and over again. The idea was to move that code
> > > into the std library.
> >
> > That's exactly what happens today with the constructors that only take
> > a std::string, so it wouldn't be any worse than what we have now,
> > would it?
>
> Sorry, I'm not sure I understand your question. Maybe you meant "any
> better than what we have"? Anyway, I've attached two outputs that show
> what I mean. The version with the const char* ctor overloads
> implemented in the library is significantly shorter in the throwing path
> (5x function call vs. 7x function call + other inlined std::string ctor
> code).
>
> >
> > > BTW the original patch was posted during Stage 3 (19.12.2013). I don't
> > > mind waiting until Stage 1 if adding exports now is a problem.
> >
> > OK, let's wait and decide how we want to do it properly in stage 1.
>
> Sure. Actually I've missed some of the other exception types in
> system_error, which should be added, too. That would eliminate the
> TODO: Add const char* ctors to all exceptions.
>
> I'd also propose moving the system_error ctor implementations into the
> library as well, for the same reasons as above.
>
> >
> > (If we're going to make various changes that impact the ABI during the
> > next stage 1 we might even want to consider changing the
> > std::exception base class to store something like a
> > std::shared_ptr<std::string> so that copying an exception object will
> > never throw an exception, which is something I've been thinking about
> > recently.)
>
> Wouldn't using std::shared_ptr<std::string> introduce an additional heap
> allocation when creating the exception, though?
> How about storing the exception message in a plain zero terminated
> string instead? This would require only one heap allocation if the
> string data is prefixed with a refcount variable. Basically,
> std::make_shared re-invented because it doesn't work with arrays.
> Or maybe implement N3640 + N3641 first (even if for library internal use
> only as a start)...
>
> Cheers,
> Oleg
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PING] Re: Add const char* constructors for exception classes in <stdexcept>
2014-05-01 16:18 ` Oleg Endo
@ 2014-05-02 15:57 ` Jonathan Wakely
2014-05-11 19:01 ` [PING] " Oleg Endo
0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Wakely @ 2014-05-02 15:57 UTC (permalink / raw)
To: Oleg Endo; +Cc: libstdc++, gcc-patches
On 1 May 2014 17:18, Oleg Endo wrote:
> Jonathan,
>
> now that we're in stage 1 again, I'd like to revive the issue below. Do
> you have any particular plans? How should we proceed?
Hi Oleg, sorry for letting the thread die in January.
We will definitely want to deal with the missing constructors in
<stdexcept> during stage 1, but I'm not sure exactly when :-)
I'll come back to this next week - ping me if you don't hear from me again!
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PING] Add const char* constructors for exception classes in <stdexcept>
2014-05-02 15:57 ` Jonathan Wakely
@ 2014-05-11 19:01 ` Oleg Endo
0 siblings, 0 replies; 11+ messages in thread
From: Oleg Endo @ 2014-05-11 19:01 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches
On 02 May 2014, at 17:57, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 1 May 2014 17:18, Oleg Endo wrote:
>> Jonathan,
>>
>> now that we're in stage 1 again, I'd like to revive the issue below. Do
>> you have any particular plans? How should we proceed?
>
> Hi Oleg, sorry for letting the thread die in January.
>
> We will definitely want to deal with the missing constructors in
> <stdexcept> during stage 1, but I'm not sure exactly when :-)
>
> I'll come back to this next week - ping me if you don't hear from me again!
And here I am, pinging... :)
If it helps, I could brush up the patch that I submitted here:
http://gcc.gnu.org/ml/gcc-patches/2013-12/msg01688.html
The thing you've mentioned regarding exception message string storage in
http://gcc.gnu.org/ml/gcc-patches/2014-01/msg01925.html
is a different issue I think.
Cheers,
Oleg
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2014-05-11 19:01 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-19 0:11 Add const char* constructors for exception classes in <stdexcept> Oleg Endo
2013-12-19 1:19 ` Jonathan Wakely
2013-12-19 15:28 ` Oleg Endo
2014-01-26 14:15 ` [PING] " Oleg Endo
2014-01-29 15:21 ` Jonathan Wakely
2014-01-29 21:17 ` Oleg Endo
2014-01-29 21:38 ` Jonathan Wakely
2014-01-29 22:45 ` Oleg Endo
2014-05-01 16:18 ` Oleg Endo
2014-05-02 15:57 ` Jonathan Wakely
2014-05-11 19:01 ` [PING] " Oleg Endo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).