[Gmp-commit] /var/hg/gmp: The C++ standard was modified so common_type now de...

mercurial at gmplib.org mercurial at gmplib.org
Wed May 7 22:33:13 UTC 2014


details:   /var/hg/gmp/rev/8a70dd4c020c
changeset: 16379:8a70dd4c020c
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Thu May 08 00:33:09 2014 +0200
description:
The C++ standard was modified so common_type now decays.

diffstat:

 ChangeLog            |   6 ++++++
 gmpxx.h              |   4 ++--
 tests/cxx/t-cxx11.cc |  13 +++++++++----
 3 files changed, 17 insertions(+), 6 deletions(-)

diffs (58 lines):

diff -r 55ff6b8d9a92 -r 8a70dd4c020c ChangeLog
--- a/ChangeLog	Mon Apr 14 07:09:29 2014 +0200
+++ b/ChangeLog	Thu May 08 00:33:09 2014 +0200
@@ -1,3 +1,9 @@
+2014-05-08  Marc Glisse  <marc.glisse at inria.fr>
+
+	* gmpxx.h (std::common_type): Remove partial specialization for two
+	identical expressions. New partial specialization for a single type.
+	* tests/cxx/t-cxx11.cc: Test it.
+
 2014-04-14  Niels Möller  <nisse at lysator.liu.se>
 
 	* doc/gmp.texi (mpz_invert): Clarify behavior in the zero ring.
diff -r 55ff6b8d9a92 -r 8a70dd4c020c gmpxx.h
--- a/gmpxx.h	Mon Apr 14 07:09:29 2014 +0200
+++ b/gmpxx.h	Thu May 08 00:33:09 2014 +0200
@@ -1232,9 +1232,9 @@
   };
 
   template <class T, class U>
-  struct common_type <__gmp_expr<T, U>, __gmp_expr<T, U> >
+  struct common_type <__gmp_expr<T, U> >
   {
-    typedef __gmp_expr<T, U> type;
+    typedef __gmp_expr<T, T> type;
   };
 
 #define __GMPXX_DECLARE_COMMON_TYPE(typ)	\
diff -r 55ff6b8d9a92 -r 8a70dd4c020c tests/cxx/t-cxx11.cc
--- a/tests/cxx/t-cxx11.cc	Mon Apr 14 07:09:29 2014 +0200
+++ b/tests/cxx/t-cxx11.cc	Thu May 08 00:33:09 2014 +0200
@@ -42,6 +42,8 @@
 
 void check_common_type ()
 {
+#define CHECK_COMMON_TYPE1(T, Res) \
+  static_assert(std::is_same<std::common_type<T>::type, Res>::value, "sorry")
 #define CHECK_COMMON_TYPE(T, U, Res) \
   static_assert(std::is_same<std::common_type<T, U>::type, Res>::value, "sorry")
 #define CHECK_COMMON_TYPE_BUILTIN1(T, Res) \
@@ -101,10 +103,13 @@
   CHECK_COMMON_TYPE (decltype(-z), decltype(-f), mpf_class);
   CHECK_COMMON_TYPE (decltype(-q), decltype(-f), mpf_class);
 
-  /* These could be broken by a naive common_type specialization */
-  CHECK_COMMON_TYPE (decltype(-z), decltype(-z), decltype(-z));
-  CHECK_COMMON_TYPE (decltype(-q), decltype(-q), decltype(-q));
-  CHECK_COMMON_TYPE (decltype(-f), decltype(-f), decltype(-f));
+  /* common_type now decays */
+  CHECK_COMMON_TYPE (decltype(-z), decltype(-z), mpz_class);
+  CHECK_COMMON_TYPE (decltype(-q), decltype(-q), mpq_class);
+  CHECK_COMMON_TYPE (decltype(-f), decltype(-f), mpf_class);
+  CHECK_COMMON_TYPE1 (decltype(-z), mpz_class);
+  CHECK_COMMON_TYPE1 (decltype(-q), mpq_class);
+  CHECK_COMMON_TYPE1 (decltype(-f), mpf_class);
 
   /* Painful */
   CHECK_COMMON_TYPE_BUILTIN (decltype(-z), mpz_class);


More information about the gmp-commit mailing list