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: throw specs on Standard destructors


On Wed, Dec 11, 2002 at 11:20:50AM -0600, Benjamin Kosnik wrote:
> On Wed, 11 Dec 2002 08:34:27 -0800
> Nathan Myers <ncm-nospam@cantrip.org> wrote:
> 
> >No.  An implementation is not required to declare destructors throw().
> >Any code that fails if they're not so declared is broken, because it
> >assumes an implementation detail that the standard doesn't specify.  
> 
> Sadly, agreed.
> 
> However, this code does compile with 2.95/2.96 (but not with 3.x series
> compilers). Adding the string and auto_ptr bits, conditionally so that
> -pedantic will remove them, seems to be the solution.

We still need to be careful not to generate a test and call
to terminate().  Maybe a function try block with empty catch
clause would suffice:

  basic_string::~basic_string() 
  #ifndef __PEDANTIC__  // (or whatever it's called)
    throw()
    try 
  #endif
      { _M_rep()->_M_dispose(this->get_allocator()); }
  #ifndef __PEDANTIC__ 
    catch(...) {}  // discard embarrassments
  #endif

Sorry, I don't recall the correct name for the cpp macro that indicates 
pedanticism or its lack, and failed to find it in the code.

It really would be better if the _M_rep, get_allocator, _M_dispose,
and __exchange_and_add functions were declared throw() too.
(_M_destroy is already.)  Then, the decl would look like

  basic_string::~basic_string() 
  #ifndef __PEDANTIC__  // (or whatever it's called)
    throw()
  #endif
      { _M_rep()->_M_dispose(this->get_allocator()); }
  #endif

Declaring __exchange_and_add as throw() would require changes
in several files, of course.

Nathan Myers
ncm-nospam@cantrip.org


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