Skip to content

CWG3181 [except.spec] Must an explicit specialization have a stronger exception specification than the primary template? #861

Description

@t3nsor

Full name of submitter: Brian Bi

Issue description: C++14 [except.spec]/4 provided as follows:

If any declaration of a function has an exception-specification that is not a noexcept-specification allowing all exceptions, all declarations, including the definition and any explicit specialization, of that function shall have a compatible exception-specification. [...]

It appears that P0003R5 removed this wording and didn't replace it with anything equivalent. However, current [except.spec]/12 still alludes to the presence of this 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); [...]

Clang and GCC currently reject explicit specializations that are noexcept(false) if the primary template was noexcept, as well as the other way around.

Suggested resolution: There does not seem to a compelling rationale for a restriction.

Edit [temp.expl.spec]/12:

Whether an explicit specialization of a function or variable template is noexcept, inline, constexpr, constinit, or consteval is determined by the explicit specialization and is independent of those properties of the template. Similarly, attributes and function-contract-specifiers appearing in the declaration of a template have no effect on an explicit specialization of that template.

Edit [except.spec]/12.3:

the exception specification is compared to that of another declaration (e.g., an explicit specialization or an overriding virtual function);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions