Martin provided this fix years ago in the PR, but I've overlooked it
until now.

2018-11-23  Martin Sebor  <mse...@redhat.com>
            Jonathan Wakely  <jwak...@redhat.com>

        PR libstdc++/65229
        * python/libstdcxx/v6/printers.py (StdBitsetPrinter): Handle
        exception thrown for std::bitset<0>.
        * testsuite/libstdc++-prettyprinters/simple.cc: Test std::bitset<0>.

Tested powerpc64le-linux, committed to trunk.


commit a77b9d48076c617f8249d285a0cbe4205a5d84c9
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Fri Nov 23 16:06:04 2018 +0000

    PR libstdc++/65229 fix pretty printer for std::bitset<0>
    
    2018-11-23  Martin Sebor  <mse...@redhat.com>
                Jonathan Wakely  <jwak...@redhat.com>
    
            PR libstdc++/65229
            * python/libstdcxx/v6/printers.py (StdBitsetPrinter): Handle
            exception thrown for std::bitset<0>.
            * testsuite/libstdc++-prettyprinters/simple.cc: Test std::bitset<0>.

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py 
b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 28733385dc9..7c3c9d00ef3 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -702,7 +702,13 @@ class StdBitsetPrinter:
         return '%s' % (self.typename)
 
     def children (self):
-        words = self.val['_M_w']
+        try:
+            # An empty bitset may not have any members which will
+            # result in an exception being thrown.
+            words = self.val['_M_w']
+        except:
+            return []
+
         wtype = words.type
 
         # The _M_w member can be either an unsigned long, or an
@@ -712,7 +718,7 @@ class StdBitsetPrinter:
             tsize = wtype.target ().sizeof
         else:
             words = [words]
-            tsize = wtype.sizeof 
+            tsize = wtype.sizeof
 
         nwords = wtype.sizeof / tsize
         result = []
@@ -848,7 +854,7 @@ class Tr1HashtableIterator(Iterator):
             self.node = self.buckets[self.bucket]
             if self.node:
                 break
-            self.bucket = self.bucket + 1        
+            self.bucket = self.bucket + 1
 
     def __iter__ (self):
         return self
@@ -951,7 +957,6 @@ class Tr1UnorderedMapPrinter:
         data = self.flatten (imap (self.format_one, StdHashtableIterator 
(self.hashtable())))
         # Zip the two iterators together.
         return izip (counter, data)
-        
 
     def display_hint (self):
         return 'map'
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc 
b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc
index 1ed8184a853..088c65dfe48 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc
@@ -41,6 +41,10 @@ main()
   std::string str = "zardoz";
 // { dg-final { note-test str "\"zardoz\"" } }
 
+  // PR 65229
+  std::bitset<0> bs0;
+// { dg-final { note-test bs0 {std::bitset} } }
+
   std::bitset<10> bs;
   bs[0] = 1;
   bs[5] = 1;

Reply via email to