2730. numeric_limits primary template definition

Section: 21.3.4 [numeric.limits] Status: Open Submitter: Richard Smith Opened: 2016-06-09 Last modified: 2017-02-25

Priority: 3

View other active issues in [numeric.limits].

View all other issues in [numeric.limits].

View all issues with Open status.


I've received this report at the project editor mail alias, and it seems like it may be worthy of a LWG issue:

I recently had this problem:

This broke the sorting for me on different platforms, and it was quite difficult to determine why. If the default numeric_limits didn't default to 0s and false values ( of N4582), and instead static_asserted, causing my code to not compile, I would have found the solution immediately.

I know that __uint128_t is non-standard, so neither GCC nor Clang is doing the wrong thing nor the right thing here. I could just submit a patch to libc++ providing the specialisations, but it doesn't fix the problem at its core.

I am wondering, what is the rationale behind the defaults being 0 and false? It seems like it is inviting a problem for any future numeric types, whether part of a library, compiler extension, and possibly even future updates to C++'s numeric types. I think it would be much better to prevent code that tries to use unspecified numeric_limits from compiling.

An alternative to this suggestion would be to still define the primary template, but not provide any of the members except is_specialized. Either way, this would make numeric_limits members SFINAEable.

Along the same lines, one might wonder why the members that only make sense for floating-point types are required to be defined to nonsense values for integer types.

[2016-11-12, Issaquah]

Sat PM: This looks like a good idea. Jonathan and Marshall will do post C++17 implementations and report back.

Proposed resolution: