This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PING] Re: Add const char* constructors for exception classes in <stdexcept>


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]