Constructor taking 64-bit integer missing on (some) Windows C++ compilers
Mihai Preda
mpreda at gmail.com
Sat Jun 6 04:28:21 UTC 2020
I'm using libgmp-dev 6.1.2 on Ubuntu myself, but the bug report
concerns an unspecified version of GMP on Windows. I have reasons to
suspect the bug is valid for the most recent GMP. Clear cause analysis
and proposed solution is included.
I'm not a Windows user myself. I develop an open-source app that users
are compiling, among others, on Windows with mingw or other c++
compilers on windows. A common habit of these c++ compilers on windows
is to have 32-bit long.
In my app I construct a mpz_class from a 64-bit unsigned integer, like this:
uint64_t h = ...;
mpz_class{h};
At this point the C++ compiler on windows (where long is 32-bit)
reports errors, see at the end. The problem is that the set of
constructors does not include one taking a 64-bit integer:
#define __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS \
__gmp_expr(signed char c) { init_si(c); } \
__gmp_expr(unsigned char c) { init_ui(c); } \
__gmp_expr(signed int i) { init_si(i); } \
__gmp_expr(unsigned int i) { init_ui(i); } \
__gmp_expr(signed short int s) { init_si(s); } \
__gmp_expr(unsigned short int s) { init_ui(s); } \
__gmp_expr(signed long int l) { init_si(l); } \
__gmp_expr(unsigned long int l) { init_ui(l); } \
__gmp_expr(float f) { init_d(f); } \
__gmp_expr(double d) { init_d(d); }
Among all in the list above, none takes a uint64_t or int64_t.
The fix could consist in having these constructors take int64_t
instead of long int, etc. I.e. take explicitly-sized typed instead of
the "long" which is variable-size.
ProofSet.h:197:90: error: call of overloaded
'__gmp_expr(<brace-enclosed initializer list>)' is ambiguous
197 | for (int i = 0; i < (1 << (p - 1)); ++i) {
hashes.push_back(hashes[i] * mpz_class{h}); }
|
^
In file included from GmpUtil.h:6,
from ProofSet.h:6,
from Gpu.cpp:4:
C:/msys64/mingw64/include/gmpxx.h:1646:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(double)'
1646 | __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/gmpxx.h:1646:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(float)'
1646 | __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/gmpxx.h:1646:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(long
unsigned int)'
1646 | __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/gmpxx.h:1646:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(long int)'
1646 | __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/gmpxx.h:1646:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(short
unsigned int)'
1646 | __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/gmpxx.h:1646:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(short
int)'
1646 | __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/gmpxx.h:1646:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(unsigned
int)'
1646 | __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/gmpxx.h:1646:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(int)'
1646 | __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/gmpxx.h:1646:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(unsigned
char)'
1646 | __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/gmpxx.h:1646:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(signed
char)'
1646 | __GMPXX_DEFINE_ARITHMETIC_CONSTRUCTORS
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/gmpxx.h:1636:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct
[1]>::__gmp_expr(__gmp_expr<__mpz_struct [1], __mpz_struct [1]>&&)'
1636 | __gmp_expr(__gmp_expr &&z) noexcept
| ^~~~~~~~~~
C:/msys64/mingw64/include/gmpxx.h:1634:3: note: candidate:
'__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr(const
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>&)'
1634 | __gmp_expr(const __gmp_expr &z) { mpz_init_set(mp, z.mp); }
More information about the gmp-bugs
mailing list