According to the norm, casting a int64_t to a int32_t (or any signed integral type to a smaller signed integral type) is 'implementation defined' until C++20 (ref: cppreference.com).
Some code of the class Integer (src/kernel/gmp++) can leads to such casts.
For example, in the method to cast an Integer into a int32_t on 64-bit machine (or any machine with sizeof(long int) = sizeof (int64_t)):
|
Integer::operator int32_t() const |
|
{ |
|
return int32_t (mpz_get_si ( (mpz_srcptr)&gmp_rep)); |
|
} |
In this case the output of mpz_get_si is a signed integral type of 64 bits and is casted into a signed integral type of 32 bits.
I think a more comprehensive proof-reading of the code in gmp++ is necessary to catch other similar problems.
According to the norm, casting a int64_t to a int32_t (or any signed integral type to a smaller signed integral type) is 'implementation defined' until C++20 (ref: cppreference.com).
Some code of the class Integer (
src/kernel/gmp++) can leads to such casts.For example, in the method to cast an Integer into a int32_t on 64-bit machine (or any machine with
sizeof(long int) = sizeof (int64_t)):givaro/src/kernel/gmp++/gmp++_int_misc.C
Lines 385 to 388 in 6fdc2a0
In this case the output of mpz_get_si is a signed integral type of 64 bits and is casted into a signed integral type of 32 bits.
I think a more comprehensive proof-reading of the code in gmp++ is necessary to catch other similar problems.