summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2012-05-31 23:31:48 +0200
committerMarc Glisse <marc.glisse@inria.fr>2012-05-31 23:31:48 +0200
commitd16b005b490eabeda823c3fb00fef9329a4cf649 (patch)
tree16a94165cc18e9e147686b0232a9c056eca7bf08
parent024f07177c7e393e9ea0ab804998ec12408bd74d (diff)
downloadgmp-d16b005b490eabeda823c3fb00fef9329a4cf649.tar.gz
Handle mpq_class(0,1)
-rw-r--r--ChangeLog5
-rw-r--r--gmpxx.h9
-rw-r--r--tests/cxx/t-constr.cc1
3 files changed, 14 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 005ada450..09e7e0114 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/gmpxx.h b/gmpxx.h
index d47757864..450f37568 100644
--- a/gmpxx.h
+++ b/gmpxx.h
@@ -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 &)