This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [test] Fixed possible loss of data warnings in tests on amd64
ClosedPublic

Authored by BillyONeal on Apr 26 2017, 5:19 PM.

Details

Summary

Fix possible loss of data warnings on amd64

In T_size_size.pass, there is an explicit template argument to std::min to ask
for unsigned, to avoid type deduction errors. However, C1XX' warnings still
hate this use, because a 64 bit value (a size_t) is being passed to a function
accepting an unsigned (a 32 bit value).

Instead, change the tests to pass around std::size_t instances, and explicitly
narrow when constructing the string type under test. This also allows
removal of explicit template arguments to std::min.

Diff Detail

Event Timeline

BillyONeal created this revision.Apr 26 2017, 5:19 PM
EricWF accepted this revision.May 4 2017, 1:08 AM

LGTM after addressing inline comments.

test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
40

The cast should happen after the subtraction, not before.

73

The cast should happen after the subtraction, not before.

This revision is now accepted and ready to land.May 4 2017, 1:08 AM
BillyONeal added inline comments.May 4 2017, 2:41 AM
test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
40

The cast happens before the subtraction because the invariant that size() is less than unsigned max is established on line 36 (by passing in an unsigned as the length).

Alternately, would it be better to just pass around size_ts here so that no casts would be necessary any longer?

EricWF added inline comments.May 4 2017, 3:13 AM
test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
40

Alternately, would it be better to just pass around size_ts here so that no casts would be necessary any longer?

Yeah, that seems more correct to me. Good catch.

BillyONeal updated this revision to Diff 98214.May 8 2017, 2:43 PM
BillyONeal marked 4 inline comments as done.
BillyONeal edited the summary of this revision. (Show Details)

Instead, change the tests to pass around std::size_t instances, and explicitly
narrow when constructing the string type under test. This also allows
removal of explicit template arguments to std::min.

EricWF accepted this revision.May 8 2017, 2:44 PM

Still LGTM.

BillyONeal closed this revision.May 8 2017, 3:08 PM