Created on 2001-06-27.00:00:00 last changed 204 months ago
[Picked up by evolution group at October 2002 meeting.]
Note (March, 2008):
The Evolution Working Group recommended closing this issue with no further consideration. See paper J16/07-0033 = WG21 N2173.
Is it okay for a static_cast to drop exception specifications?
void f() throw(int); int main () { static_cast<void (*)() throw()>(f); // Okay? void (*p)() throw() = f; // Error }
The fact that a static_cast is defined, more or less, as an initialization suggests that a check ought to be made.
One tricky point: this is another case where the general rule that the reverse of an implicit cast is allowed as a static_cast bites you -- the reverse conversion doesn't drop exception specifications, and so is okay. Perhaps this should be treated like casting away constness.
Mike Miller comments : I don't think that case can arise. According to 14.5 [except.spec],
An exception-specification shall appear only on a function declarator in a function, pointer, reference, or pointer to member declaration or definition.
We strengthened that in issue 87 (voted to DR status in Copenhagen) to
An exception-specification shall appear only on a function declarator for a function type, pointer to function type, reference to function type, or pointer to member function type that is the top-level type of a declaration or definition, or on such a type appearing as a parameter or return type in a function declarator.
As I read that, you can't put an exception-specification on the type-id in a static_cast, which means that a static_cast can only weaken, not strengthen, the exception specification.
The core WG discussed this at the 10/01 meeting and agreed.
History | |||
---|---|---|---|
Date | User | Action | Args |
2008-03-17 00:00:00 | admin | set | messages: + msg1630 |
2008-03-17 00:00:00 | admin | set | status: extension -> nad |
2002-11-08 00:00:00 | admin | set | messages: + msg792 |
2002-11-08 00:00:00 | admin | set | status: nad -> extension |
2001-11-09 00:00:00 | admin | set | status: open -> nad |
2001-06-27 00:00:00 | admin | create |