Title
Coordinating “throws anything” specifications
Status
cd4
Section
14.5 [except.spec]
Submitter
Richard Smith

Created on 2014-11-18.00:00:00 last changed 94 months ago

Messages

Date: 2016-01-15.00:00:00

Proposed resolution (January, 2016):

  1. Change 14.5 [except.spec] paragraph 12 as follows:

  2. A The set of potential exceptions of a given context is either a type a set of types that might be thrown as an exception or a pseudo-type, denoted by “any”, that represents the situation where an exception of an arbitrary type might be thrown; the (conceptual) set of all types is used to denote that an exception of arbitrary type might be thrown. A subexpression e1 of an expression e is an immediate subexpression if there is no subexpression e2 of e such that e1 is a subexpression of e2.
  3. Delete 14.5 [except.spec] paragraph 13:

  4. The set of potential exceptions of a function, function pointer, or member function pointer f is defined as follows:

    • If the exception specification of f is the set of all types, the set consists of the pseudo-type “any”.

    • Otherwise, the set consists of every type in the exception specification of f.

  5. Change 14.5 [except.spec] paragraph 14 as follows:

  6. 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 function call (7.6.1.3 [expr.call]):

      • If its postfix-expression is a (possibly parenthesized) id-expression (_N4567_.5.1.1 [expr.prim.general]), class member access (7.6.1.5 [expr.ref]), or pointer-to-member operation (7.6.4 [expr.mptr.oper]) whose cast-expression is an id-expression, S is the set of potential exceptions types in the exception specification of the entity selected by the contained id-expression (after overload resolution, if applicable).

      • Otherwise, if the postfix-expression has type “noexcept function” or “pointer to noexcept function”, S is the empty set.

      • Otherwise, S contains the pseudo-type “any” is the set of all types.

    • If e implicitly invokes a function (such as an overloaded operator, an allocation function in a new-expression, or a destructor if e is a full-expression (6.9.1 [intro.execution])), S is the set of potential exceptions types in the exception specification of the function.

    • If e initializes an object of type D using an inherited constructor for a class of type B (11.9.4 [class.inhctor.init]), S also contains the sets of potential exceptions of the implied constructor invocations for subobjects of D that are not subobjects of B (including default argument expressions used in such invocations) as selected by overload resolution, and the sets of potential exceptions of the initialization of non-static data members from brace-or-equal-initializers (11.9.3 [class.base.init]).

    • If e is a throw-expression (7.6.18 [expr.throw]), S consists of the type of the exception object that would be initialized by the operand, if present, or is the pseudo-type “any” set of all types otherwise.

    • If e is a dynamic_cast expression that casts to a reference type and requires a run-time check (7.6.1.7 [expr.dynamic.cast]), S consists of the type std::bad_cast.

    • 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.

    • If e is a new-expression with a non-constant expression in the noptr-new-declarator (7.6.2.8 [expr.new]), S consists of the type std::bad_array_new_length.

    [Example: Given the following declarations

      void f() throw(int);
      void g();
      struct A { A(); };
      struct B { B() noexcept; };
      struct D { D() throw (double); };
    

    the set of potential exceptions for some sample expressions is:

    • for f(), the set consists of int;

    • for g(), the set consists of “any” is the set of all types;

    • for new A, the set consists of “any” is the set of all types;

    • for B(), the set is empty;

    • for new D, the set consists of “any” and double is the set of all types.

    end example]

  7. Change 14.5 [except.spec] paragraph 16 as follows:

  8. Given an An implicitly-declared special member function f of some class X, the set of potential exceptions of the implicitly-declared special member function f is considered to have an implicit exception specification that consists of all the members from the following sets:...
  9. Delete the normative text of 14.5 [except.spec] paragraph 17 and merge the example with the preceding paragraph:

  10. An implicitly-declared special member function ( 11.4.4 [special]) is considered to have an implicit exception specification, as follows, where S is the set of potential exceptions of the implicitly-declared special member function:

    • if S contains the pseudo-type “any”, the implicit exception specification is the set of all types;

    • otherwise, the implicit exception specification contains all the types in S.

    [Example:...

Date: 2015-11-15.00:00:00

Additional note (November, 2015):

The base text underlying the preceding proposed resolution was changed at the October, 2015 meeting by the adoption of paper P0136R1. As a result, this issue has been returned to "drafting" status to allow reconciliation of the two sets of changes.

Date: 2015-10-15.00:00:00

Proposed resolution (October, 2015) [SUPERSEDED]:

  1. Change 14.5 [except.spec] paragraph 13 as follows:

  2. A The set of potential exceptions of a given context is either a type a set of types that might be thrown as an exception or a pseudo-type, denoted by “any”, that represents the situation where an exception of an arbitrary type might be thrown; the (conceptual) set of all types is used to denote that an exception of arbitrary type might be thrown. A subexpression e1 of an expression e is an immediate subexpression if there is no subexpression e2 of e such that e1 is a subexpression of e2.
  3. Delete 14.5 [except.spec] paragraph 14:

  4. The set of potential exceptions of a function, function pointer, or member function pointer f is defined as follows:

    • If the exception specification of f is the set of all types, the set consists of the pseudo-type “any”.

    • Otherwise, the set consists of every type in the exception specification of f.

  5. Change 14.5 [except.spec] paragraph 15 as follows:

  6. 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 function call (7.6.1.3 [expr.call]):

      • If its postfix-expression is a (possibly parenthesized) id-expression (_N4567_.5.1.1 [expr.prim.general]), class member access (7.6.1.5 [expr.ref]), or pointer-to-member operation (7.6.4 [expr.mptr.oper]) whose cast-expression is an id-expression, S is the set of potential exceptions types in the exception specification of the entity selected by the contained id-expression (after overload resolution, if applicable).

      • Otherwise, S contains the pseudo-type “any” is the set of all types.

    • If e implicitly invokes a function (such as an overloaded operator, an allocation function in a new-expression, or a destructor if e is a full-expression (6.9.1 [intro.execution])), S is the set of potential exceptions types in the exception specification of the function.

    • if e is a throw-expression (7.6.18 [expr.throw]), S consists of the type of the exception object that would be initialized by the operand, if present, or is the pseudo-type “any” set of all types otherwise.

    • if e is a dynamic_cast expression that casts to a reference type and requires a run-time check (7.6.1.7 [expr.dynamic.cast]), S consists of the type std::bad_cast.

    • 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.

    • if e is a new-expression with a non-constant expression in the noptr-new-declarator (7.6.2.8 [expr.new]), S consists of the type std::bad_array_new_length.

    [Example: Given the following declarations

      void f() throw(int);
      void g();
      struct A { A(); };
      struct B { B() noexcept; };
      struct D() { D() throw (double); };
    

    the set of potential exceptions for some sample expressions is:

    • for f(), the set consists of int;

    • for g(), the set consists of “any” is the set of all types;

    • for new A, the set consists of “any” is the set of all types;

    • for B(), the set is empty;

    • for new D, the set consists of “any” and double is the set of all types. [Note: This set conceptually includes the type double. —end note]

    end example]

  7. Change 14.5 [except.spec] paragraph 16 as follows:

  8. Given a A member function f of some class X, where f is an inheriting constructor (_N4527_.12.9 [class.inhctor]) or an implicitly-declared special member function, the set of potential exceptions of the implicitly-declared member function f is considered to have an implicit exception specification that consists of all the members from the following sets...
  9. Delete the normative portion of 14.5 [except.spec] paragraph 17 and merge the note and example into the preceding paragraph, as follows:

  10. An inheriting constructor (_N4527_.12.9 [class.inhctor]) and an implicitly-declared special member function ( 11.4.4 [special]) are considered to have an implicit exception specification, as follows, where S is the set of potential exceptions of the implicitly-declared member function:

    • if S contains the pseudo-type “any”, the implicit exception specification is the set of all types;

    • otherwise, the implicit exception specification contains all the types in S.

    [Note: An instantiation of an inheriting constructor template...

Date: 2016-02-15.00:00:00

[Adopted at the February, 2016 meeting.]

The resolutions of issues 330 and 1351 use different terminology for an exception specification that can throw anything: the former refers to a “(conceptual) set of all types,” while the latter uses a “pseudo-type, denoted by 'any'.” These should be unified.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: tentatively ready -> cd4
2016-02-15 00:00:00adminsetmessages: + msg5711
2016-02-15 00:00:00adminsetstatus: ready -> tentatively ready
2015-11-10 00:00:00adminsetmessages: + msg5586
2015-11-10 00:00:00adminsetmessages: + msg5585
2015-11-10 00:00:00adminsetstatus: drafting -> ready
2014-11-18 00:00:00admincreate