[gcc r11-4946] libstdc++: Simplify __numeric_traits definition

Jonathan Wakely redi@gcc.gnu.org
Thu Nov 12 14:37:00 GMT 2020


https://gcc.gnu.org/g:d21776ef90361e66401cd99c8ff0d98b46d3b0d6

commit r11-4946-gd21776ef90361e66401cd99c8ff0d98b46d3b0d6
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Nov 12 13:31:02 2020 +0000

    libstdc++: Simplify __numeric_traits definition
    
    This changes the __numeric_traits primary template to assume its
    argument is an integer type. For the three floating point types that are
    supported by __numeric_traits_floating an explicit specialization of
    __numeric_traits chooses the right base class.
    
    This improves the failure mode for using __numeric_traits with an
    unsupported type. Previously it would use __numeric_traits_floating as
    the base class, and give somewhat obscure errors for trying to access
    the static data members. Now it will use __numeric_traits_integer which
    has a static_assert to check for supported types.
    
    As a side effect of this change there is no need to instantiate
    __conditional_type to decide which base class to use.
    
    libstdc++-v3/ChangeLog:
    
            * include/ext/numeric_traits.h (__numeric_traits): Change
            primary template to always derive from __numeric_traits_integer.
            (__numeric_traits<float>, __numeric_traits<double>)
            (__numeric_traits<long double>): Add explicit specializations.

Diff:
---
 libstdc++-v3/include/ext/numeric_traits.h | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/libstdc++-v3/include/ext/numeric_traits.h b/libstdc++-v3/include/ext/numeric_traits.h
index c29f9f21d1a..2cac7f1d1ed 100644
--- a/libstdc++-v3/include/ext/numeric_traits.h
+++ b/libstdc++-v3/include/ext/numeric_traits.h
@@ -176,19 +176,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Value>
     const int __numeric_traits_floating<_Value>::__max_exponent10;
 
+#undef __glibcxx_floating
+#undef __glibcxx_max_digits10
+#undef __glibcxx_digits10
+#undef __glibcxx_max_exponent10
+
   template<typename _Value>
     struct __numeric_traits
-    : public __conditional_type<__is_integer_nonstrict<_Value>::__value,
-				__numeric_traits_integer<_Value>,
-				__numeric_traits_floating<_Value> >::__type
+    : public __numeric_traits_integer<_Value>
+    { };
+
+  template<>
+    struct __numeric_traits<float>
+    : public __numeric_traits_floating<float>
+    { };
+
+  template<>
+    struct __numeric_traits<double>
+    : public __numeric_traits_floating<double>
+    { };
+
+  template<>
+    struct __numeric_traits<long double>
+    : public __numeric_traits_floating<long double>
     { };
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
-#undef __glibcxx_floating
-#undef __glibcxx_max_digits10
-#undef __glibcxx_digits10
-#undef __glibcxx_max_exponent10
-
 #endif


More information about the Libstdc++-cvs mailing list