summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--gmp-h.in8
-rw-r--r--gmpxx.h4
-rw-r--r--mpz/init.c2
-rw-r--r--mpz/inits.c2
-rw-r--r--tests/cxx/t-cxx11.cc8
6 files changed, 26 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 1894376f7..bf3d25236 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2015-04-07 Marc Glisse <marc.glisse@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@google.com>
* mpf/set_q.c: Rewrite, mainly to use mpn_div_q..
diff --git a/gmp-h.in b/gmp-h.in
index ecc8a3720..8276e097f 100644
--- a/gmp-h.in
+++ b/gmp-h.in
@@ -345,7 +345,11 @@ typedef __mpq_struct *mpq_ptr;
__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 mp_bitcnt_t mpz_hamdist (mpz_srcptr, mpz_srcptr) __GMP_NOTHROW __
__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 --git a/gmpxx.h b/gmpxx.h
index bf36b9aca..10b655add 100644
--- a/gmpxx.h
+++ b/gmpxx.h
@@ -1589,11 +1589,11 @@ public:
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 --git a/mpz/init.c b/mpz/init.c
index 45ed21e4b..425a66a36 100644
--- a/mpz/init.c
+++ b/mpz/init.c
@@ -33,7 +33,7 @@ see https://www.gnu.org/licenses/. */
#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 --git a/mpz/inits.c b/mpz/inits.c
index 925905144..3f35a899e 100644
--- a/mpz/inits.c
+++ b/mpz/inits.c
@@ -33,7 +33,7 @@ see https://www.gnu.org/licenses/. */
#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 --git a/tests/cxx/t-cxx11.cc b/tests/cxx/t-cxx11.cc
index 1f314ff03..8a4d4d459 100644
--- a/tests/cxx/t-cxx11.cc
+++ b/tests/cxx/t-cxx11.cc
@@ -38,6 +38,14 @@ void check_noexcept ()
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 ()