gmpxx: bug in declaration of __gmp_set_expr

Torbjorn Granlund tg at swox.com
Tue Aug 12 16:08:05 CEST 2008


Marc Glisse <marc.glisse at normalesup.org> writes:

  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
  
I am too C++ ignorant to understand this.

Your example seem somewhat strange, since it accesses __gmp_set_expr
which surely is meant to be internal.

For suggested C++ changes, a patch and a change log and an explanation
of what problem is solved, or what improvements result, would be the
preferred form of contribution...

I hope to read up on C++ in the not too distant future.

-- 
Torbjörn


More information about the gmp-bugs mailing list