This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

3922. It's unclear whether numeric_limits can be specialized by users

Section: 17.3.5.1 [numeric.limits.general] Status: New Submitter: Christopher Di Bella Opened: 2023-04-14 Last modified: 2023-04-18

Priority: 3

View other active issues in [numeric.limits.general].

View all other issues in [numeric.limits.general].

View all issues with New status.

Discussion:

16.4.5.2.1 [namespace.std]/p2 notes that "unless explicitly prohibited", a user may conditionally specialize any class template for program-defined types. 17.3.5.1 [numeric.limits.general]/p1 doesn't explicitly prohibit this, but it does create a bit of a grey area with its wording because it describes numeric_limits as a class template describing "the implementation's representation" of "the arithmetic types".

Since this type is about what the implementation provides, and about arithmetic types only, it's not clear whether a user can specialize it for their own library type such as ns::int256. ns::int256 isn't an arithmetic type (despite resembling one), so one can interpret 16.4.5.2.1 [namespace.std]/p2's (b) condition to mean that numeric_limits<ns::int256> needs to be explicitly specialized as if it were the primary template.

Daniel:

This issue has overlap with LWG 3923.

[2023-05-24; Reflector poll]

Set priority to 3 after reflector poll.

Several votes for Tentatively Ready with Option A.

Proposed resolution:

This wording is relative to N4944.

[Drafting Note: Two mutually exclusive options are prepared, depicted below by Option A and Option B, respectively.]

Option A: (This assumes that the above described scenario is intended to be supported)

  1. Add the following new paragraph at the end of 17.3.5.1 [numeric.limits.general] as indicated:

    [Drafting Note: The particular wording form "emulating an arithmetic type" has been borrowed from Table 99 — Cpp17Clock requirements [tab:time.clock] and 29.5.1 [time.duration.general] p2, respectively.]

    -?- The numeric_limits template may be specialized for program-defined types emulating arithmetic types.

Option B: (This assumes that the above described scenario is not intended to be supported)

  1. Add the following new paragraph at the end of 17.3.5.1 [numeric.limits.general] as indicated:

    [Drafting Note: The particular wording form has been borrowed from 17.12.4.1 [coroutine.handle.general] p2 and 20.2.9.1 [allocator.traits.general] p1, respectively.]

    -?- If a program declares an explicit or partial specialization of numeric_limits, the program is ill-formed, no diagnostic required.