@@ -815,10 +815,7 @@ namespace tr2
operator>>=(size_type __pos)
{
if (__builtin_expect(__pos < this->_M_Nb, 1))
- {
- this->_M_do_right_shift(__pos);
- this->_M_do_sanitize();
- }
+ this->_M_do_right_shift(__pos);
else
this->_M_do_reset();
return *this;
@@ -60,8 +60,7 @@ namespace tr2
this->_M_w[__wshift] = this->_M_w[0] << __offset;
}
- //// std::fill(this->_M_w.begin(), this->_M_w.begin() + __wshift,
- //// static_cast<_WordT>(0));
+ std::fill_n(this->_M_w.begin(), __wshift, _WordT(0));
}
}
@@ -88,8 +87,7 @@ namespace tr2
this->_M_w[__limit] = this->_M_w[_M_w.size()-1] >> __offset;
}
- ////std::fill(this->_M_w.begin() + __limit + 1, this->_M_w.end(),
- //// static_cast<_WordT>(0));
+ std::fill_n(this->_M_w.end() - __wshift, __wshift, _WordT(0));
}
}
new file mode 100644
@@ -0,0 +1,37 @@
+// { dg-do run { target c++11 } }
+
+// PR libstdc++/115399
+// std::tr2::dynamic_bitset shift behaves differently from std::bitset
+
+#include <tr2/dynamic_bitset>
+#include <testsuite_hooks.h>
+
+void
+test_left_shift()
+{
+ std::tr2::dynamic_bitset<> b(65);
+ b[0] = 1;
+ auto b2 = b << 64;
+ VERIFY(b2[64] == 1);
+ VERIFY(b2[0] == 0);
+ b <<= 64;
+ VERIFY( b2 == b );
+}
+
+void
+test_right_shift()
+{
+ std::tr2::dynamic_bitset<> b(65);
+ b[64] = 1;
+ auto b2 = b >> 64;
+ VERIFY(b2[64] == 0);
+ VERIFY(b2[0] == 1);
+ b >>= 64;
+ VERIFY( b2 == b );
+}
+
+int main()
+{
+ test_left_shift();
+ test_right_shift();
+}