This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PING] Re: Add const char* constructors for exception classes in <stdexcept>
- From: Oleg Endo <oleg dot endo at t-online dot de>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 29 Jan 2014 22:17:27 +0100
- Subject: Re: [PING] Re: Add const char* constructors for exception classes in <stdexcept>
- Authentication-results: sourceware.org; auth=none
- References: <1387411826 dot 2455 dot 325 dot camel at yam-132-YW-E178-FTW> <CAH6eHdTK93RwatvT+m_1TLv7Ni=yQ=wDi6v7Hq=jT=O=ZSffzw at mail dot gmail dot com> <1387466908 dot 2455 dot 355 dot camel at yam-132-YW-E178-FTW> <1390745736 dot 22215 dot 207 dot camel at yam-132-YW-E178-FTW> <20140129152136 dot GA21735 at redhat dot com>
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