[libcxx-dev] charconv.to.chars/integral.bool.fail.cpp is incorrect
Jens Maurer via libcxx-dev
libcxx-dev at lists.llvm.org
Tue Jul 23 12:14:21 PDT 2019
On 23/07/2019 20.21, Marshall Clow wrote:
> On Thu, Jul 18, 2019 at 9:50 PM Stephan T. Lavavej via libcxx-dev <libcxx-dev at lists.llvm.org <mailto:libcxx-dev at lists.llvm.org>> wrote:
> test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp claims that "Integral cannot be bool." and expects that calling to_chars() with a bool should fail to compile. This is an incorrect interpretation of the Standardese. MSVC's STL implements the overload set exactly as depicted in the Standard, so this test case compiles successfully.
> The Standardese is N4820 20.19.2 [charconv.to.chars]/7 "Remarks: The implementation shall provide overloads for all signed and unsigned integer types and char as the type of the parameter value." Observe that these are depicted as overloads - not as a template.
> I suspect that that was not Jens' intention when he wrote the wording.
> cc'ing him.
Yes, that's unintended.
The facility is specified using overloads (not templates), because
it is anticipated that WG14 might want to use it at some point
in the future.
So, we have a bool -> int promotion that makes "to_chars(true)" call
"to_chars(1)", even though "bool" is none of the mentioned types.
Option 1: re-specify using a template (similar to rotl / rotr)
Option 2: add a deleted overload for "bool"
By the way, char16_t has the same problem, and likely
char32_t as well. Those were expressly discussed as
"not wanted" in LEWG, if I remember correctly.
I thought at that time that the ambiguous conversion
to int / unsigned int etc. will fix this, but
promotions are better than conversions, and there is
only one promotion.
I'm weakly in favor of adding the deleted overloads.
More information about the libcxx-dev