119. Should virtual functions be allowed to strengthen the exception specification?

Section: 16.4.6.13 [res.on.exception.handling] Status: TC1 Submitter: Judy Ward Opened: 1998-12-15 Last modified: 2016-01-28 10:19:27 UTC

Priority: Not Prioritized

View other active issues in [res.on.exception.handling].

View all other issues in [res.on.exception.handling].

View all issues with TC1 status.

Discussion:

Section 16.4.6.13 [res.on.exception.handling] states:

"An implementation may strengthen the exception-specification for a function by removing listed exceptions."

The problem is that if an implementation is allowed to do this for virtual functions, then a library user cannot write a class that portably derives from that class.

For example, this would not compile if ios_base::failure::~failure had an empty exception specification:

#include <ios>
#include <string>

class D : public std::ios_base::failure {
public:
        D(const std::string&);
        ~D(); // error - exception specification must be compatible with 
              // overridden virtual function ios_base::failure::~failure()
};

Proposed resolution:

Change Section 16.4.6.13 [res.on.exception.handling] from:

     "may strengthen the exception-specification for a function"

to:

     "may strengthen the exception-specification for a non-virtual function".