Topic: Defect Report: Exception specifications processed inconsistently


Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1999/06/08
Raw View
The standard is inconsistent about constness inside exception specification=
s.

struct X{};
struct Y:X{};

const Y bar(){return Y();}

void foo()throw(const X)
{
  throw bar();
}

It is unclear whether calling foo will result in a call to unexpected.
According to 15.4, [except.spec]/7, only two cases are treated
specially with regard to inheritance: If "class X" appears in the
type-id-list, or if "class X*" appears in the type-id-list. Neither is
the case here, so foo only allows exceptions of the same type (const
X). As a result, unexpected should be called.

OTOH, the intent of exception specification appears to allow an
implementation of this example as

void foo()
try{
  throw bar();
}catch(const X){
  throw;
}catch(...){
  std::unexpected();
}

According to 15.3, this replacement code would catch the exception, so
unexpected would not be called.

Proposed resolution: Change 15.4/7 to read
"A function is said to <em>allow</em> all exceptions objects of all
types E for which one of the types T in the type-id-list would be a
handler, according to 15.3."

Please let me know if you need further information.

Regards,
Martin v. L=F6wis
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]