This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2618. Substitution during deduction should exclude exception specifications

Section: 13.10.3.1  [temp.deduct.general]     Status: C++23     Submitter: Christof Meerwald     Date: 2021-11-27

[Accepted as a DR at the November, 2022 meeting.]

Subclause 13.10.3.1 [temp.deduct.general] paragraph 7 specifies:

The substitution occurs in all types and expressions that are used in the function type and in template parameter declarations. The expressions include not only constant expressions such as those that appear in array bounds or as nontype template arguments but also general expressions (i.e., non-constant expressions) inside sizeof, decltype, and other contexts that allow non-constant expressions. The substitution proceeds in lexical order and stops when a condition that causes deduction to fail is encountered. If substitution into different declarations of the same function template would cause template instantiations to occur in a different order or not at all, the program is ill-formed; no diagnostic required.

[Note 4: The equivalent substitution in exception specifications is done only when the noexcept-specifier is instantiated, at which point a program is ill-formed if the substitution results in an invalid type or expression. —end note]

The note says that substitution into the noexcept-specifier occurs late, but the normative text does not support that, because the exception specification is part of the function type.

Subclause 13.10.3.1 [temp.deduct.general] paragraph 8 specifies:

Only invalid types and expressions in the immediate context of the function type, its template parameter types, and its explicit-specifier can result in a deduction failure.

However, paragraph 7 does not mention the explicit-specifier when describing the substitution.

Proposed resolution (approved by CWG 2022-09-09):

Change in 13.10.3.1 [temp.deduct.general] paragraph 7 as follows:

The deduction substitution loci are

The substitution occurs in all types and expressions that are used in the function type and in template parameter declarations deduction substitution loci. ...

Change in 13.10.3.1 [temp.deduct.general] paragraph 8 as follows:

... Only invalid Invalid types and expressions can result in a deduction failure only in the immediate context of the function type, its template parameter types, and its explicit-specifier deduction substitution loci can result in a deduction failure.