mpark / variant

C++17 `std::variant` for C++11/14/17
https://mpark.github.io/variant
Boost Software License 1.0
659 stars 88 forks source link

Warning: implicit conversion loses integer precision #23

Closed jfirebaugh closed 7 years ago

jfirebaugh commented 7 years ago

When compiling with -Wshorten-64-to-32 on platforms where std::size_t is unsigned long, many warnings of the following form are produced:

include/mpark/variant.hpp:754:24: warning: implicit conversion loses integer precision: 'std::size_t' (aka 'unsigned long') to 'unsigned int' [-Wshorten-64-to-32]
          lhs.index_ = rhs.index();
                     ~ ^~~~~~~~~~~
viboes commented 7 years ago

Could you give more context so that we know what lhs and rhs are?

jfirebaugh commented 7 years ago

Sure -- as far as I can tell (not super familiar with the implementation), this warning will occur regardless of the alternative types of the actual variant in use, because the lhs and rhs involved here are internal to the implementation. The error location is here, so:

mpark commented 7 years ago

Thanks for reporting this @jfirebaugh! I've fixed this in https://github.com/mpark/variant/commit/d8fd0fbba727f0f2f757a05ae7a86e14c3b5982c