rttr icon indicating copy to clipboard operation
rttr copied to clipboard

Support x64-android

Open FrankXie05 opened this issue 1 year ago • 5 comments

Describe the bug

Implicit type conversion rules in C++. In C++, if two values of different types are operated on or compared, the compiler attempts an implicit type conversion to convert one value to the type of the other. This implicit type conversion may result in loss of precision, overflow, or incorrect results。

That's why I used the explicit conversion result.

Environment

OS: Ubuntu 20.04.6 LTS Compiler: gcc 9.4.0

Use: vcpkg

To reproduce: Run command:

./vcpkg install rttr:x64-android

FrankXie05 avatar Mar 12 '24 08:03 FrankXie05

Error log: install-arm64-android-dbg-out.log

404 NOT FOUND.

The patch will turn off the compiler message. But will the result still be correct, given different precision of the compared types?

dg0yt avatar Mar 13 '24 07:03 dg0yt

Original error from https://github.com/microsoft/vcpkg/issues/37123:

D:/vcpkg/buildtrees/rttr/src/e36f02ecd4-afbbb37f66.clean/src/rttr/../rttr/detail/conversion/number_conversion.h:137:16: error: implicit conversion from 'std::numeric_limits<int>::type' (aka 'int') to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-const-int-float-conversion]
    if (from > std::numeric_limits<T>::max())
             ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/vcpkg/buildtrees/rttr/src/e36f02ecd4-afbbb37f66.clean/src/rttr/../rttr/detail/variant/variant_data_converter.h:1060:16: note: in instantiation of function template specialization 'rttr::detail::convert_to<float, int>' requested here
        return convert_to(from, to);
               ^
...
D:/vcpkg/buildtrees/rttr/src/e36f02ecd4-afbbb37f66.clean/src/rttr/../rttr/detail/conversion/number_conversion.h:139:21: error: implicit conversion from 'std::numeric_limits<int>::type' (aka 'int') to 'float' changes value from -2147483647 to -2147483648 [-Werror,-Wimplicit-const-int-float-conversion]
    else if (from < -std::numeric_limits<T>::max())
                  ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/vcpkg/buildtrees/rttr/src/e36f02ecd4-afbbb37f66.clean/src/rttr/../rttr/detail/conversion/number_conversion.h:137:16: error: implicit conversion from 'std::numeric_limits<long>::type' (aka 'long') to 'float' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-const-int-float-conversion]
    if (from > std::numeric_limits<T>::max())
             ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/vcpkg/buildtrees/rttr/src/e36f02ecd4-afbbb37f66.clean/src/rttr/../rttr/detail/variant/variant_data_converter.h:1065:16: note: in instantiation of function template specialization 'rttr::detail::convert_to<float, long>' requested here
        return convert_to(from, to);
               ^
...

Note the changed values.

dg0yt avatar Mar 13 '24 07:03 dg0yt

The patch will turn off the compiler message. But will the result still be correct, given different precision of the compared types?

There is a legitimate concern that the comparison of integers and floats is itself an implicit problem.

The solution I can think of is:

  1. Convert them all to the same type to ensure the same accuracy.(double is slightly better than float because the range is larger)
  2. Use epsilon for comparison。

FrankXie05 avatar Mar 13 '24 08:03 FrankXie05

Like this:

    double max_val = static_cast<double>(std::numeric_limits<T>::max());
    double min_val = static_cast<double>(std::numeric_limits<T>::min());

FrankXie05 avatar Mar 13 '24 08:03 FrankXie05