Add const char* constructors for exception classes in <stdexcept>

Ed Smith-Rowland 3dw4rd@verizon.net
Thu Dec 19 12:08:00 GMT 2013


On 12/18/2013 07:10 PM, 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.
>
> 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.
Oleg,

I tried to add these back in 
http://gcc.gnu.org/ml/libstdc++/2012-10/msg00165.html
and http://gcc.gnu.org/ml/libstdc++/2012-10/msg00099.html.

Look at the discussion for why not maybe?  I didn't get much from the 
comments myself.

Maybe you'll have better luck.

Ed



More information about the Libstdc++ mailing list