diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2012-05-31 23:31:48 +0200 |
---|---|---|
committer | Marc Glisse <marc.glisse@inria.fr> | 2012-05-31 23:31:48 +0200 |
commit | d16b005b490eabeda823c3fb00fef9329a4cf649 (patch) | |
tree | 16a94165cc18e9e147686b0232a9c056eca7bf08 | |
parent | 024f07177c7e393e9ea0ab804998ec12408bd74d (diff) | |
download | gmp-d16b005b490eabeda823c3fb00fef9329a4cf649.tar.gz |
Handle mpq_class(0,1)
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | gmpxx.h | 9 | ||||
-rw-r--r-- | tests/cxx/t-constr.cc | 1 |
3 files changed, 14 insertions, 1 deletions
@@ -1,3 +1,8 @@ +2012-05-31 Marc Glisse <marc.glisse@inria.fr> + + * gmpxx.h (mpq_class::mpq_class): Handle mpq_class(0,1). + * tests/cxx/t-constr.cc: Test it. + 2012-05-30 Torbjorn Granlund <tege@gmplib.org> * mpn/x86_64 (FUNC_ENTRY): New name for DOS64_ENTRY. @@ -1641,7 +1641,14 @@ public: explicit __gmp_expr(const char *s, int base = 0) { mpq_init (mp); - if (mpq_set_str(mp, s, base) != 0) + // If s is the literal 0, we meant to call another constructor. + // If s just happens to evaluate to 0, we would crash, so whatever. + if (s == 0) + { + // Don't turn mpq_class(0,0) into 0 + mpz_set_si(mpq_denref(mp), base); + } + else if (mpq_set_str(mp, s, base) != 0) { mpq_clear (mp); throw std::invalid_argument ("mpq_set_str"); diff --git a/tests/cxx/t-constr.cc b/tests/cxx/t-constr.cc index 6d588d31d..fb26c3370 100644 --- a/tests/cxx/t-constr.cc +++ b/tests/cxx/t-constr.cc @@ -320,6 +320,7 @@ check_mpq (void) const char *a = "FFFF"; int base = 16; mpq_class b(a, base); ASSERT_ALWAYS(b == 65535u); + mpq_class c(0, 1); ASSERT_ALWAYS(c == 0); } // mpq_class(const std::string &) |