]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix std::tr2::dynamic_bitset support for alternate characters
authorJonathan Wakely <jwakely@redhat.com>
Sat, 18 Nov 2023 21:09:53 +0000 (21:09 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 21 Nov 2023 15:58:21 +0000 (15:58 +0000)
libstdc++-v3/ChangeLog:

* include/tr2/dynamic_bitset (dynamic_bitset): Pass zero and one
characters to _M_copy_from_string.
* testsuite/tr2/dynamic_bitset/string.cc: New test.

libstdc++-v3/include/tr2/dynamic_bitset
libstdc++-v3/testsuite/tr2/dynamic_bitset/string.cc [new file with mode: 0644]

index dd2845bd26b6551efd6f3381cc954bdf206ef823..ffdce82590fd0752290f40be81528306cbe26fb6 100644 (file)
@@ -622,7 +622,7 @@ namespace tr2
          // Watch for npos.
          this->_M_Nb = (__n > __str.size() ? __str.size() - __pos : __n);
          this->resize(this->_M_Nb);
-         this->_M_copy_from_string(__str, __pos, __n);
+         this->_M_copy_from_string(__str, __pos, __n, __zero, __one);
        }
 
       /**
diff --git a/libstdc++-v3/testsuite/tr2/dynamic_bitset/string.cc b/libstdc++-v3/testsuite/tr2/dynamic_bitset/string.cc
new file mode 100644 (file)
index 0000000..c7d0efa
--- /dev/null
@@ -0,0 +1,36 @@
+// { dg-do run { target c++11 } }
+
+#include <tr2/dynamic_bitset>
+#include <string>
+#include <testsuite_hooks.h>
+
+void
+test_string_ctor()
+{
+  std::tr2::dynamic_bitset<> b("101001");
+  VERIFY( b[0] == true );
+  VERIFY( b[1] == false );
+  VERIFY( b[2] == false );
+  VERIFY( b[3] == true );
+  VERIFY( b[4] == false );
+  VERIFY( b[5] == true );
+}
+
+void
+test_alt_chars()
+{
+  std::string str = "xOIOIOIOx";
+  std::tr2::dynamic_bitset<> b(str, 1, 6, 'I', 'O');
+  VERIFY( b[0] == false );
+  VERIFY( b[1] == true );
+  VERIFY( b[2] == false );
+  VERIFY( b[3] == true );
+  VERIFY( b[4] == false );
+  VERIFY( b[5] == true );
+}
+
+int main()
+{
+  test_string_ctor();
+  test_alt_chars();
+}