This is an archive of the discontinued LLVM Phabricator instance.

[libc++][test] Fix MSVC warnings C6054, C6001, C4242
ClosedPublic

Authored by fsb4000 on Aug 6 2022, 11:24 AM.

Details

Summary

warning C4242: '=': conversion from 'int' to 'char', possible loss of data
and double to long double.

Also

llvm-project\libcxx\test\std\utilities\format\format.functions\format_tests.h(121) : warning C6054: String 'begin' might not be zero-terminated.: Lines: 88, 89, 90, 91, 92, 109, 110, 121

llvm-project\libcxx\test\std\utilities\format\format.functions\format_tests.h(121) : warning C6001: Using uninitialized memory 'begin'.: Lines: 88, 89, 90, 91, 92, 109, 110, 121

llvm-project\libcxx\test\std\utilities\format\format.functions\format_tests.h(125) : warning C6001: Using uninitialized memory 'end'.: Lines: 88, 89, 90, 91, 92, 125

and -NaN is formatted like "-nan(ind)"

Also I found something else.
Currently this test fails on MSVC with

Format string   answer is '{:#g}'
Expected output answer is '0.'
Actual output   answer is '0.00000'

This is tested there: https://github.com/llvm/llvm-project/blob/486a3c4662cb052329b96537da18893d73138b64/libcxx/test/std/utilities/format/format.functions/format_tests.h#L2035

I don't know what standard says about it but libfmt agrees with MSVC: https://gcc.godbolt.org/z/vd38r5W9x

Diff Detail

Event Timeline

fsb4000 created this revision.Aug 6 2022, 11:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2022, 11:24 AM
fsb4000 requested review of this revision.Aug 6 2022, 11:24 AM
Herald added a reviewer: Restricted Project. · View Herald TranscriptAug 6 2022, 11:24 AM
Mordante requested changes to this revision.Aug 6 2022, 11:46 AM
Mordante added a subscriber: Mordante.

Also I found something else.
Currently this test fails on MSVC with

Format string   answer is '{:#g}'
Expected output answer is '0.'
Actual output   answer is '0.00000'

This seems like a bug, looking at http://eel.is/c++draft/format#string.std-6 the trailing zeros should remain. It seems I missed that. Good catch.

For now I put this on request changes to remove it from the review queue, so we can discuss what to do about the NaNs.

libcxx/test/std/utilities/format/format.functions/format_tests.h
1031

MSVC STL is wrong per
http://eel.is/c++draft/format#string.std-22

I added code to not directly use the result of std::to_chars since I know it can give the "wrong" results.
https://github.com/llvm/llvm-project/blob/main/libcxx/include/__format/formatter_floating_point.h#L582

But let's discuss this further on MSVC STL's Discord.

This revision now requires changes to proceed.Aug 6 2022, 11:46 AM
fsb4000 updated this revision to Diff 450593.Aug 6 2022, 10:59 PM

now MSVC STL formats -NaN correctly: https://github.com/microsoft/STL/pull/3001
Thanks @Mordante !

fsb4000 retitled this revision from [libc++][test] Fix MSVC warnings C6054, C6001, C4242 and -NaN is formatted differently on MSVC to [libc++][test] Fix MSVC warnings C6054, C6001, C4242.Aug 6 2022, 11:00 PM
Mordante accepted this revision.Aug 7 2022, 2:49 AM

LGTM, thanks! Please update the commit message before committing by removing the -NaN and the '{:#g}' issue parts.
(I am busy resolving the #g bug in libc++.)

This revision is now accepted and ready to land.Aug 7 2022, 2:49 AM