public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8646] libstdc++: Fix -Wshift-count-overflow warning in std::bitset
@ 2024-01-31  9:44 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2024-01-31  9:44 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:86302e1a76a4af29b4de401685d3822f3eb96899

commit r14-8646-g86302e1a76a4af29b4de401685d3822f3eb96899
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Jan 20 21:09:28 2024 +0000

    libstdc++: Fix -Wshift-count-overflow warning in std::bitset
    
    This shift only happens if the unsigned long long type is wider than
    unsigned long but the compiler warns when it sees the shift, without
    caring if it's reachable.
    
    Use the preprocessor to compare the sizes and just reuse _M_to_ulong()
    if sizeof(long) == sizeof(long long).
    
    libstdc++-v3/ChangeLog:
    
            * include/std/bitset (_Base_bitset::_M_do_to_ullong): Avoid
            -Wshift-count-overflow warning.

Diff:
---
 libstdc++-v3/include/std/bitset | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index c169269698a9..3243c6497314 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -320,17 +320,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
     _GLIBCXX14_CONSTEXPR unsigned long long
     _Base_bitset<_Nw>::_M_do_to_ullong() const
     {
-      const bool __dw = sizeof(unsigned long long) > sizeof(unsigned long);
-      for (size_t __i = 1 + __dw; __i < _Nw; ++__i)
+#if __SIZEOF_LONG_LONG__ == __SIZEOF_LONG__
+      return _M_do_to_ulong();
+#else
+      for (size_t __i = 2; __i < _Nw; ++__i)
 	if (_M_w[__i])
 	  __throw_overflow_error(__N("_Base_bitset::_M_do_to_ullong"));
 
-      if (__dw)
-	return _M_w[0] + (static_cast<unsigned long long>(_M_w[1])
+      return _M_w[0] + (static_cast<unsigned long long>(_M_w[1])
 			  << _GLIBCXX_BITSET_BITS_PER_WORD);
-      return _M_w[0];
-    }
 #endif
+    }
+#endif // C++11
 
   template<size_t _Nw>
     _GLIBCXX14_CONSTEXPR size_t

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-31  9:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-31  9:44 [gcc r14-8646] libstdc++: Fix -Wshift-count-overflow warning in std::bitset Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).