[Gmp-commit] /var/hg/gmp: mpz_init cannot throw.

mercurial at gmplib.org mercurial at gmplib.org
Thu Apr 7 20:50:10 UTC 2016


details:   /var/hg/gmp/rev/835f8974ff6e
changeset: 17067:835f8974ff6e
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Thu Apr 07 22:50:07 2016 +0200
description:
mpz_init cannot throw.

diffstat:

 ChangeLog            |  8 ++++++++
 gmp-h.in             |  8 ++++++--
 gmpxx.h              |  4 ++--
 mpz/init.c           |  2 +-
 mpz/inits.c          |  2 +-
 tests/cxx/t-cxx11.cc |  8 ++++++++
 6 files changed, 26 insertions(+), 6 deletions(-)

diffs (105 lines):

diff -r 8ccd8e7de27b -r 835f8974ff6e ChangeLog
--- a/ChangeLog	Sun Apr 03 16:50:36 2016 +0200
+++ b/ChangeLog	Thu Apr 07 22:50:07 2016 +0200
@@ -1,3 +1,11 @@
+2015-04-07  Marc Glisse  <marc.glisse at inria.fr>
+
+	* gmp-h.in (__GMP_NOTHROW): Prefer noexcept to throw().
+	(mpz_init, mpz_inits): Mark as __GMP_NOTHROW.
+	* mpz/init.c, mpz/inits.c: Likewise.
+	* gmpxx.h (mpz_class): Mark default and move constructors noexcept.
+	* tests/cxx/t-cxx11.cc: Check noexcept.
+
 2016-04-02  Torbjörn Granlund  <torbjorng at google.com>
 
 	* mpf/set_q.c: Rewrite, mainly to use mpn_div_q..
diff -r 8ccd8e7de27b -r 835f8974ff6e gmp-h.in
--- a/gmp-h.in	Sun Apr 03 16:50:36 2016 +0200
+++ b/gmp-h.in	Thu Apr 07 22:50:07 2016 +0200
@@ -345,7 +345,11 @@
    __GMP_ATTRIBUTE_PURE.  */
 
 #if defined (__cplusplus)
+#if __cplusplus >= 201103L
+#define __GMP_NOTHROW  noexcept
+#else
 #define __GMP_NOTHROW  throw ()
+#endif
 #else
 #define __GMP_NOTHROW
 #endif
@@ -849,13 +853,13 @@
 __GMP_DECLSPEC void mpz_import (mpz_ptr, size_t, int, size_t, int, size_t, const void *);
 
 #define mpz_init __gmpz_init
-__GMP_DECLSPEC void mpz_init (mpz_ptr);
+__GMP_DECLSPEC void mpz_init (mpz_ptr) __GMP_NOTHROW;
 
 #define mpz_init2 __gmpz_init2
 __GMP_DECLSPEC void mpz_init2 (mpz_ptr, mp_bitcnt_t);
 
 #define mpz_inits __gmpz_inits
-__GMP_DECLSPEC void mpz_inits (mpz_ptr, ...);
+__GMP_DECLSPEC void mpz_inits (mpz_ptr, ...) __GMP_NOTHROW;
 
 #define mpz_init_set __gmpz_init_set
 __GMP_DECLSPEC void mpz_init_set (mpz_ptr, mpz_srcptr);
diff -r 8ccd8e7de27b -r 835f8974ff6e gmpxx.h
--- a/gmpxx.h	Sun Apr 03 16:50:36 2016 +0200
+++ b/gmpxx.h	Thu Apr 07 22:50:07 2016 +0200
@@ -1589,11 +1589,11 @@
   mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); }
 
   // constructors and destructor
-  __gmp_expr() { mpz_init(mp); }
+  __gmp_expr() __GMPXX_NOEXCEPT { mpz_init(mp); }
 
   __gmp_expr(const __gmp_expr &z) { mpz_init_set(mp, z.mp); }
 #if __GMPXX_USE_CXX11
-  __gmp_expr(__gmp_expr &&z)
+  __gmp_expr(__gmp_expr &&z) noexcept
   { *mp = *z.mp; mpz_init(z.mp); }
 #endif
   template <class T>
diff -r 8ccd8e7de27b -r 835f8974ff6e mpz/init.c
--- a/mpz/init.c	Sun Apr 03 16:50:36 2016 +0200
+++ b/mpz/init.c	Thu Apr 07 22:50:07 2016 +0200
@@ -33,7 +33,7 @@
 #include "gmp-impl.h"
 
 void
-mpz_init (mpz_ptr x)
+mpz_init (mpz_ptr x) __GMP_NOTHROW
 {
   static const mp_limb_t dummy_limb=0xc1a0;
   ALLOC (x) = 0;
diff -r 8ccd8e7de27b -r 835f8974ff6e mpz/inits.c
--- a/mpz/inits.c	Sun Apr 03 16:50:36 2016 +0200
+++ b/mpz/inits.c	Thu Apr 07 22:50:07 2016 +0200
@@ -33,7 +33,7 @@
 #include "gmp-impl.h"
 
 void
-mpz_inits (mpz_ptr x, ...)
+mpz_inits (mpz_ptr x, ...) __GMP_NOTHROW
 {
   static const mp_limb_t dummy_limb=0xc1a0;
   va_list  ap;
diff -r 8ccd8e7de27b -r 835f8974ff6e tests/cxx/t-cxx11.cc
--- a/tests/cxx/t-cxx11.cc	Sun Apr 03 16:50:36 2016 +0200
+++ b/tests/cxx/t-cxx11.cc	Thu Apr 07 22:50:07 2016 +0200
@@ -38,6 +38,14 @@
   static_assert(noexcept(q1 = std::move(q2)), "sorry");
   static_assert(noexcept(f1 = std::move(f2)), "sorry");
   static_assert(noexcept(q1 = std::move(z1)), "sorry");
+
+  // Only mpz has lazy allocation for now
+  static_assert(std::is_nothrow_default_constructible<mpz_class>::value, "sorry");
+  static_assert(std::is_nothrow_move_constructible<mpz_class>::value, "sorry");
+  static_assert(!std::is_nothrow_default_constructible<mpq_class>::value, "sorry");
+  static_assert(!std::is_nothrow_move_constructible<mpq_class>::value, "sorry");
+  static_assert(!std::is_nothrow_default_constructible<mpf_class>::value, "sorry");
+  static_assert(!std::is_nothrow_move_constructible<mpf_class>::value, "sorry");
 }
 
 void check_common_type ()


More information about the gmp-commit mailing list