<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 18, 2019 at 9:50 PM Stephan T. Lavavej via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org">libcxx-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
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.<br>
<br>
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.<br></blockquote><div><br></div><div>I suspect that that was not Jens' intention when he wrote the wording.</div><div>cc'ing him.</div><div><br></div><div>-- Marshall</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">If implemented as overloads, here's what happens:<br>
<br>
C:\Temp>type woof.cpp<br>
#include <stdio.h><br>
<br>
void ToChars(char) { puts("char"); }<br>
void ToChars(signed char) { puts("signed char"); }<br>
void ToChars(unsigned char) { puts("unsigned char"); }<br>
void ToChars(short) { puts("short"); }<br>
void ToChars(unsigned short) { puts("unsigned short"); }<br>
void ToChars(int) { puts("int"); }<br>
void ToChars(unsigned int) { puts("unsigned int"); }<br>
void ToChars(long) { puts("long"); }<br>
void ToChars(unsigned long) { puts("unsigned long"); }<br>
void ToChars(long long) { puts("long long"); }<br>
void ToChars(unsigned long long) { puts("unsigned long long"); }<br>
void ToChars(float) { puts("float"); }<br>
void ToChars(double) { puts("double"); }<br>
void ToChars(long double) { puts("long double"); }<br>
<br>
int main() {<br>
    ToChars(false);<br>
}<br>
<br>
C:\Temp>cl /EHsc /nologo /W4 /std:c++17 /permissive- woof.cpp && woof<br>
woof.cpp<br>
int<br>
<br>
C:\Temp>clang-cl -m64 /EHsc /nologo /W4 /std:c++17 /permissive- -fno-ms-compatibility woof.cpp && woof<br>
int<br>
<br>
C1XX and Clang agree: the int overload is called. This is because bool undergoes a Promotion to int, and that's an exact match for int, while all other types require a Conversion from int to that type.<br>
<br>
This test case should be reworked. I mention it, instead of simply fixing the test case, because it indicates that libcxx's implementation of to_chars() for integral types is also incorrect.<br>
<br>
Thanks,<br>
STL<br>
_______________________________________________<br>
libcxx-dev mailing list<br>
<a href="mailto:libcxx-dev@lists.llvm.org" target="_blank">libcxx-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-dev</a><br>
</blockquote></div></div>