3177. Limit permission to specialize variable templates to program-defined types

Section: 16.4.5.2.1 [namespace.std] Status: C++23 Submitter: Johel Ernesto Guerrero Peña Opened: 2018-12-11 Last modified: 2023-11-22

Priority: 3

View other active issues in [namespace.std].

View all other issues in [namespace.std].

View all issues with C++23 status.

Discussion:

The permission denoted by [namespace.std]/3 should be limited to program-defined types.

[2018-12-21 Reflector prioritization]

Set Priority to 3

Previous resolution [SUPERSEDED]:

This wording is relative to N4791.

  1. Change 16.4.5.2.1 [namespace.std] as indicated:

    -2- Unless explicitly prohibited, a program may add a template specialization for any standard library class template to namespace std provided that (a) the added declaration depends on at least one program-defined type and (b) the specialization meets the standard library requirements for the original template.(footnote 174)

    -3- The behavior of a C++ program is undefined if it declares an explicit or partial specialization of any standard library variable template, except where explicitly permitted by the specification of that variable template, provided that the added declaration depends on at least one program-defined type.

[2022-08-24; LWG telecon]

Each variable template that grants permission to specialize already states requirements more precisely than proposed here anyway. For example, disable_sized_range only allows it for cv-unqualified program-defined types. Adding less precise wording here wouldn't be an improvement. Add a note to make it clear we didn't just forget to say something here, and to remind us to state requirements for each variable template in future.

[2022-08-25; Jonathan Wakely provides improved wording]

[2022-09-28; Reflector poll]

Set status to Tentatively Ready after seven votes in favour during reflector poll.

[2022-11-12 Approved at November 2022 meeting in Kona. Status changed: Voting → WP.]

Proposed resolution:

This wording is relative to N4910.