Title
Exception specification of specialization vs. primary template
Status
open
Section
14.5 [except.spec]
Submitter
Brian Bi

Created on 2026-03-10.00:00:00 last changed 2 days ago

Messages

Date: 2026-04-23.06:04:56

Suggested resolution (option 2):

  1. Change in 13.9.4 [temp.expl.spec] paragraph 12 as follows:

    Whether an explicit specialization of a function or variable template is inline, constexpr, constinit, or consteval or has a non-throwing exception specification is determined by the explicit specialization and is independent of those properties of the template. Similarly, attributes and function-contract-specifier s appearing in the declaration of a template have no effect on an explicit specialization of that template.
  2. Change in 14.5 [except.spec] bullet 12.3 as follows:

    An exception specification is considered to be needed when:
    • ...
    • the exception specification is compared to that of another declaration (e.g., an explicit specialization or an overriding virtual function);
    • ...
Date: 2026-04-23.06:04:56

Possible resolution (option 1):

Change in 14.5 [except.spec] paragraph 3 as follows:

If a declaration of a function does not have a noexcept-specifier , the declaration has a potentially throwing exception specification unless it is a destructor or a deallocation function or is defaulted on its first declaration, in which cases the exception specification is as specified below and no other declaration for that function shall have a noexcept-specifier . In an explicit instantiation (13.9.3 [temp.explicit]) a noexcept-specifier may be specified, but is not required. If a noexcept-specifier is specified in an explicit instantiation, the exception specification shall be the same as the exception specification of all other declarations of that function. A diagnostic is required only if the exception specifications are not the same within a single translation unit. The program is ill-formed if an explicit specialization has a potentially-throwing exception specification, but the corresponding primary template has a non-throwing exception specification.
Date: 2026-03-10.00:00:00

(From submission #861.)

Paper P0003R5 removed wording that required consistency between the exception specification of a primary template and any specialization. However, 14.5 [except.spec] paragraph 12 still alludes to such a rule:

An exception specification is considered to be needed when:
  • ...
  • the exception specification is compared to that of another declaration (e.g., an explicit specialization or an overriding virtual function);
  • ...
History
Date User Action Args
2026-04-23 06:04:56adminsetmessages: + msg8550
2026-04-22 20:32:25adminsetmessages: + msg8549
2026-03-10 00:00:00admincreate