diff mbox series

Avoid -Woverflow warning in __numeric_limits_integer

Message ID 20190503191330.GA28600@redhat.com
State New
Headers show
Series Avoid -Woverflow warning in __numeric_limits_integer | expand

Commit Message

Jonathan Wakely May 3, 2019, 7:13 p.m. UTC
This is the same fix as was done for std::numeric_limits in r183905.

	PR libstdc++/52119
	* include/ext/numeric_traits.h (__glibcxx_min): Avoid integer
	overflow warning with -Wpedantic -Wsystem-headers.

Tested powerpc64le-linux, committed to trunk.
commit 6320e854115f7bb9b3c943ee09c1a6a87deafb74
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu May 2 23:52:40 2019 +0100

    Avoid -Woverflow warning in __numeric_limits_integer
    
    This is the same fix as was done for std::numeric_limits in r183905.
    
            PR libstdc++/52119
            * include/ext/numeric_traits.h (__glibcxx_min): Avoid integer
            overflow warning with -Wpedantic -Wsystem-headers.
diff mbox series

Patch

diff --git a/libstdc++-v3/include/ext/numeric_traits.h b/libstdc++-v3/include/ext/numeric_traits.h
index 67993fdc58e..43ba1c8740a 100644
--- a/libstdc++-v3/include/ext/numeric_traits.h
+++ b/libstdc++-v3/include/ext/numeric_traits.h
@@ -39,13 +39,13 @@  namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // Compile time constants for builtin types.
-  // Sadly std::numeric_limits member functions cannot be used for this.
+  // In C++98 std::numeric_limits member functions cannot be used for this.
 #define __glibcxx_signed(_Tp) ((_Tp)(-1) < 0)
 #define __glibcxx_digits(_Tp) \
   (sizeof(_Tp) * __CHAR_BIT__ - __glibcxx_signed(_Tp))
 
 #define __glibcxx_min(_Tp) \
-  (__glibcxx_signed(_Tp) ? (_Tp)1 << __glibcxx_digits(_Tp) : (_Tp)0)
+  (__glibcxx_signed(_Tp) ? -__glibcxx_max(_Tp) - 1 : (_Tp)0)
 
 #define __glibcxx_max(_Tp) \
   (__glibcxx_signed(_Tp) ? \