Skip to content

Commit

Permalink
libstdc++: Fix vector<bool> printer tests to work in debug mode
Browse files Browse the repository at this point in the history
This fixes a compilation error in debug mode, due to std::_Bit_reference
not being defined, because it's in namespace std::__cxx1998 instead. We
can refer to it as vector<bool>::reference instead, which always works.

That fixes some compilation errors in debug mode, but the tests fail at
run-time instead because the printers for vector<bool> helpers are only
registered for the std namespace, not std::__cxx1998. That is fixed by
using add_container to register the printers instead of add_version, as
the former registers them in the std and std::__cxx1998 namespaces.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/printers.py (StdBitReferencePrinter): Use
	'std::vector<bool>::reference' as type name, not _Bit_reference.
	(build_libstdcxx_dictionary): Register printers for vector<bool>
	types in debug mode too.
	* testsuite/libstdc++-prettyprinters/simple.cc: Adjust expected
	output for invalid _Bit_reference. Use vector<bool>::reference
	instead of _Bit_reference.
	* testsuite/libstdc++-prettyprinters/simple11.cc: Likewise.

(cherry picked from commit c883d1d)
  • Loading branch information
jwakely committed Nov 25, 2021
1 parent a82a323 commit 88b9997
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions libstdc++-v3/python/libstdcxx/v6/printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,14 @@ def to_string(self):
return bool(self.val['_M_p'].dereference() & (1 << self.val['_M_offset']))

class StdBitReferencePrinter:
"Print std::_Bit_reference"
"Print std::vector<bool>::reference"

def __init__(self, typename, val):
self.val = val

def to_string(self):
if not self.val['_M_p']:
return 'invalid std::_Bit_reference'
return 'invalid std::vector<bool>::reference'
return bool(self.val['_M_p'].dereference() & (self.val['_M_mask']))

class StdTuplePrinter:
Expand Down Expand Up @@ -2083,11 +2083,11 @@ def build_libstdcxx_dictionary ():
StdDequeIteratorPrinter)
libstdcxx_printer.add_version('__gnu_cxx::', '__normal_iterator',
StdVectorIteratorPrinter)
libstdcxx_printer.add_version('std::', '_Bit_iterator',
libstdcxx_printer.add_container('std::', '_Bit_iterator',
StdBitIteratorPrinter)
libstdcxx_printer.add_version('std::', '_Bit_const_iterator',
libstdcxx_printer.add_container('std::', '_Bit_const_iterator',
StdBitIteratorPrinter)
libstdcxx_printer.add_version('std::', '_Bit_reference',
libstdcxx_printer.add_container('std::', '_Bit_reference',
StdBitReferencePrinter)
libstdcxx_printer.add_version('__gnu_cxx::', '_Slist_iterator',
StdSlistIteratorPrinter)
Expand Down
14 changes: 7 additions & 7 deletions libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ main()
std::vector<bool>::iterator vbIt0;
// { dg-final { note-test vbIt0 {non-dereferenceable iterator for std::vector<bool>} } }

std::_Bit_reference br = *vb.begin();
std::vector<bool>::reference br = *vb.begin();
// { dg-final { note-test br {true} } }
std::_Bit_reference br2 = *vbIt2;
std::vector<bool>::reference br2 = *vbIt2;
// { dg-final { note-test br2 {true} } }
std::_Bit_reference br3 = *vbIt3;
std::vector<bool>::reference br3 = *vbIt3;
// { dg-final { note-test br3 {false} } }
std::_Bit_reference br4 = *vbIt4;
std::vector<bool>::reference br4 = *vbIt4;
// { dg-final { note-test br4 {false} } }
std::_Bit_reference br5 = *vbIt5;
std::vector<bool>::reference br5 = *vbIt5;
// { dg-final { note-test br5 {true} } }

std::_Bit_reference br0;
// { dg-final { note-test br0 {invalid std::_Bit_reference} } }
std::vector<bool>::reference br0;
// { dg-final { note-test br0 {invalid std::vector<bool>::reference} } }

__gnu_cxx::slist<int> sll;
sll.push_front(23);
Expand Down
14 changes: 7 additions & 7 deletions libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ main()
std::vector<bool>::iterator vbIt0;
// { dg-final { note-test vbIt0 {non-dereferenceable iterator for std::vector<bool>} } }

std::_Bit_reference br = *vb.begin();
std::vector<bool>::reference br = *vb.begin();
// { dg-final { note-test br {true} } }
std::_Bit_reference br2 = *vbIt2;
std::vector<bool>::reference br2 = *vbIt2;
// { dg-final { note-test br2 {true} } }
std::_Bit_reference br3 = *vbIt3;
std::vector<bool>::reference br3 = *vbIt3;
// { dg-final { note-test br3 {false} } }
std::_Bit_reference br4 = *vbIt4;
std::vector<bool>::reference br4 = *vbIt4;
// { dg-final { note-test br4 {false} } }
std::_Bit_reference br5 = *vbIt5;
std::vector<bool>::reference br5 = *vbIt5;
// { dg-final { note-test br5 {true} } }

std::_Bit_reference br0;
// { dg-final { note-test br0 {invalid std::_Bit_reference} } }
std::vector<bool>::reference br0;
// { dg-final { note-test br0 {invalid std::vector<bool>::reference} } }

__gnu_cxx::slist<int> sll;
sll.push_front(23);
Expand Down

0 comments on commit 88b9997

Please sign in to comment.