Title
Incorrect result for noexcept(typeid(v))
Status
c++17
Section
14.5 [except.spec]
Submitter
Mike Miller

Created on 2015-10-26.00:00:00 last changed 36 months ago

Messages

Date: 2016-11-15.00:00:00

Proposed resolution (November, 2016):

Change 14.5 [except.spec] bullet 13.6 as follows:

The set of potential exceptions of an expression e is empty if e is a core constant expression (7.7 [expr.const]). Otherwise, it is the union of the sets of potential exceptions of the immediate subexpressions of e, including default argument expressions used in a function call, combined with a set S defined by the form of e, as follows:

  • ...

  • If e is a typeid expression applied to a glvalue expression whose type is (possibly parenthesized) built-in unary * operator applied to a pointer to a polymorphic class type (7.6.1.8 [expr.typeid]), S consists of the type std::bad_typeid. [Example: ...

Date: 2016-11-15.00:00:00

[Adopted at the November, 2016 meeting as part of paper P0003R5.]

Consider the following example:

    struct B { virtual void f() { } };
    struct D : B { } d;
    bool b = noexcept(typeid(d));

According to 7.6.2.7 [expr.unary.noexcept] paragraph 3, the value of b should be false, because 14.5 [except.spec] bullet 14.6 says,

  • If e is a typeid expression applied to a glvalue expression whose type is a polymorphic class type (7.6.1.8 [expr.typeid]), S consists of the type std::bad_typeid.

and d is such an expression. This is clearly bogus, as the expression cannot possibly throw; according to 7.6.1.8 [expr.typeid] paragraph 2, the condition under which the exception might be thrown is:

If the glvalue expression is obtained by applying the unary * operator to a pointer69 and the pointer is a null pointer value (7.3.12 [conv.ptr]), the typeid expression throws an exception (14.2 [except.throw]) of a type that would match a handler of type std::bad_typeid exception (17.7.5 [bad.typeid]).
History
Date User Action Args
2018-02-27 00:00:00adminsetstatus: ready -> c++17
2017-02-06 00:00:00adminsetmessages: + msg5722
2015-10-26 00:00:00admincreate