[PATCH] D27540: [libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss of data", part 3/7.

Stephan T. Lavavej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 8 12:14:17 PST 2016


STL_MSFT added a comment.

I can't possibly defend C1XX's behavior in your foo() scenario - but the pair scenarios being fixed here are different. pair<A, B>'s constructor from (X&&, Y&&) is perfect forwarding, so while the compiler can see that literals are being passed to (int&&, int&&), when it instantiates the constructor's definition, it just sees short being constructed from a perfectly-forwarded int, and warns about truncation there. C1XX doesn't attempt to "see through" the function call and notice that the arguments were literals. Its behavior is arguably desirable because the instantiation happens once per TU, and yet there may be other calls that are passing runtime-valued ints.

I chose static_cast<short> here because it was non-invasive, although ugly. There's a more invasive but prettier possibility - change the shorts to longs so that widening instead of truncation happens. I could do that if you want.


https://reviews.llvm.org/D27540





More information about the cfe-commits mailing list