PR libstdc++/65229 fix pretty printer for std::bitset<0>
authorMartin Sebor <msebor@redhat.com>
Fri, 23 Nov 2018 16:12:03 +0000 (16:12 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 23 Nov 2018 16:12:03 +0000 (16:12 +0000)
2018-11-23  Martin Sebor  <msebor@redhat.com>
    Jonathan Wakely  <jwakely@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>.

Co-Authored-By: Jonathan Wakely <jwakely@redhat.com>
From-SVN: r266409

libstdc++-v3/ChangeLog
libstdc++-v3/python/libstdcxx/v6/printers.py
libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc

index 2d86cc3efb44da9b2e6d634f5b26a9a5da3bae03..6898733042d7a9b6ef9b790e202ee7bd71031af4 100644 (file)
@@ -1,3 +1,11 @@
+2018-11-23  Martin Sebor  <msebor@redhat.com>
+           Jonathan Wakely  <jwakely@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>.
+
 2018-11-23  Jonathan Wakely  <jwakely@redhat.com>
 
        PR libstdc++/87308 (partial)
index 28733385dc977330342c1f05a7022439d4b0d215..7c3c9d00ef309d32a26d44c297f92a6841f681fa 100644 (file)
@@ -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'
index 1ed8184a853cd0b8309e0dc4f7957e5cfa6765ad..088c65dfe48456721d7f957297ede377bdc6306d 100644 (file)
@@ -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;