gmpxx: bug in declaration of __gmp_set_expr

Marc Glisse marc.glisse at normalesup.org
Mon Aug 11 16:10:38 CEST 2008


On Fri, 8 Aug 2008, Marc Glisse wrote:

> trying some modifications on gmpxx, I noticed an issue with the way 
> __gmp_set_expr is declared/defined

After some reading on function specialization (which apparently exists
but only for full specialization), it seems like the smallest change
would be to replace the old declarations:

template <class T, class U>
void __gmp_set_expr(mpz_ptr, const __gmp_expr<T, U> &);
template <class T, class U>
void __gmp_set_expr(mpq_ptr, const __gmp_expr<T, U> &);
template <class T, class U>
void __gmp_set_expr(mpf_ptr, const __gmp_expr<T, U> &);

by the following matrix:

template <class T> void __gmp_set_expr(mpz_ptr, const __gmp_expr<mpz_t, T> &);
template <class T> void __gmp_set_expr(mpz_ptr, const __gmp_expr<mpq_t, T> &);
template <class T> void __gmp_set_expr(mpz_ptr, const __gmp_expr<mpf_t, T> &);
template <class T> void __gmp_set_expr(mpq_ptr, const __gmp_expr<mpz_t, T> &);
template <class T> void __gmp_set_expr(mpq_ptr, const __gmp_expr<mpq_t, T> &);
template <class T> void __gmp_set_expr(mpq_ptr, const __gmp_expr<mpf_t, T> &);
template <class T> void __gmp_set_expr(mpf_ptr, const __gmp_expr<mpz_t, T> &);
template <class T> void __gmp_set_expr(mpf_ptr, const __gmp_expr<mpq_t, T> &);
template <class T> void __gmp_set_expr(mpf_ptr, const __gmp_expr<mpf_t, T> &);

In a slightly longer term, the __gmp_set_expr(mp*_t, const mp*_class&)
should IMHO become overloads instead of specializations, but it does not
really matter.

A simple way to detect that there is something wrong:

     mpz_class a=1;
     mpz_t z; mpz_init(z);
     __gmp_set_expr(z,a+a); // works
     __gmp_set_expr(z,a); // currently fails


-- 
Marc Glisse


More information about the gmp-bugs mailing list