public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r9-9384] Have std::vector printer's iterator return bool for vector<bool> Date: Tue, 20 Apr 2021 18:53:36 +0000 (GMT) [thread overview] Message-ID: <20210420185336.3BA5C39730F5@sourceware.org> (raw) https://gcc.gnu.org/g:6cc765a7917004478770f27bade1ecbb55906ae0 commit r9-9384-g6cc765a7917004478770f27bade1ecbb55906ae0 Author: Michael Weghorn <m.weghorn@posteo.de> Date: Wed Jun 19 22:57:06 2019 +0000 Have std::vector printer's iterator return bool for vector<bool> Have the pretty-printer for 'std::vector<bool>' return a value of type 'bool' rather than an 'int'. This way, the type is clear and that can be used for better display and a 'gdb.Value' constructed from the returned value will have type 'bool' again, not e.g. 'long long' as happened previously (at least with GDB 8.2.1 on amd64). 2019-06-19 Michael Weghorn <m.weghorn@posteo.de> Jonathan Wakely <jwakely@redhat.com> PR libstdc++/90945 * python/libstdcxx/v6/printers.py (StdVectorPrinter._iterator): Use values of type bool for vector<bool> elements. * testsuite/libstdc++-prettyprinters/simple.cc: Test vector<bool>. * testsuite/libstdc++-prettyprinters/simple11.cc: Likewise. Co-Authored-By: Jonathan Wakely <jwakely@redhat.com> (cherry picked from commit 36d0dada6773d7fd7c5ace64c90e723930a3b81e) Diff: --- libstdc++-v3/python/libstdcxx/v6/printers.py | 12 +++++------- libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc | 10 ++++++++++ libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc | 10 ++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 3082b0e4d8c..32b8210414a 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -422,16 +422,12 @@ class StdVectorPrinter: if self.bitvec: if self.item == self.finish and self.so >= self.fo: raise StopIteration - elt = self.item.dereference() - if elt & (1 << self.so): - obit = 1 - else: - obit = 0 + elt = bool(self.item.dereference() & (1 << self.so)) self.so = self.so + 1 if self.so >= self.isize: self.item = self.item + 1 self.so = 0 - return ('[%d]' % count, obit) + return ('[%d]' % count, elt) else: if self.item == self.finish: raise StopIteration @@ -442,7 +438,7 @@ class StdVectorPrinter: def __init__(self, typename, val): self.typename = strip_versioned_namespace(typename) self.val = val - self.is_bool = val.type.template_argument(0).code == gdb.TYPE_CODE_BOOL + self.is_bool = val.type.template_argument(0).code == gdb.TYPE_CODE_BOOL def children(self): return self._iterator(self.val['_M_impl']['_M_start'], @@ -482,6 +478,8 @@ class StdVectorIteratorPrinter: return 'non-dereferenceable iterator for std::vector' return str(self.val['_M_current'].dereference()) +# TODO add printer for vector<bool>'s _Bit_iterator and _Bit_const_iterator + class StdTuplePrinter: "Print a std::tuple" diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc index 5b70e2b3159..86b7c27d861 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc @@ -117,6 +117,16 @@ main() std::vector<int>::iterator viter0; // { dg-final { note-test viter0 {non-dereferenceable iterator for std::vector} } } + std::vector<bool> vb; + vb.reserve(100); + vb.push_back(true); + vb.push_back(true); + vb.push_back(false); + vb.push_back(false); + vb.push_back(true); + vb.erase(vb.begin()); +// { dg-final { regexp-test vb {std::(__debug::)?vector<bool> of length 4, capacity 128 = \\{true, false, false, true\\}} } } + __gnu_cxx::slist<int> sll; sll.push_front(23); sll.push_front(47); diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc index d24af91d0ea..5d47bdcd648 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc @@ -110,6 +110,16 @@ main() std::vector<int>::iterator viter0; // { dg-final { note-test viter0 {non-dereferenceable iterator for std::vector} } } + std::vector<bool> vb; + vb.reserve(100); + vb.push_back(true); + vb.push_back(true); + vb.push_back(false); + vb.push_back(false); + vb.push_back(true); + vb.erase(vb.begin()); +// { dg-final { regexp-test vb {std::(__debug::)?vector<bool> of length 4, capacity 128 = \\{true, false, false, true\\}} } } + __gnu_cxx::slist<int> sll; sll.push_front(23); sll.push_front(47);
reply other threads:[~2021-04-20 18:53 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210420185336.3BA5C39730F5@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).