diff mbox

RFC: fix std::unique_ptr pretty-printer

Message ID 874no54jph.fsf@fleche.redhat.com
State New
Headers show

Commit Message

Tom Tromey Aug. 14, 2012, 2:44 p.m. UTC
>>>>> "Jonathan" == Jonathan Wakely <jwakely.gcc@gmail.com> writes:

Jonathan> I prefer it as unique_ptr<datum> but I'm probably not your typical
Jonathan> user of the pretty printers, so if anyone else has an opinion please
Jonathan> share it.

I prefer it too.  Here's the updated patch.  Let me know what you think.

Tom

2012-08-14  Tom Tromey  <tromey@redhat.com>

	* testsuite/libstdc++-prettyprinters/cxx11.cc (struct datum):
	New.
	(global): New global.
	(main): Add test for unique_ptr.
	* python/libstdcxx/v6/printers.py
	(UniquePointerPrinter.to_string): Extract the pointer and also
	print its type.

Comments

Jonathan Wakely Aug. 15, 2012, 2:49 p.m. UTC | #1
On 14 August 2012 15:44, Tom Tromey wrote:
>>>>>> "Jonathan" == Jonathan Wakely <jwakely.gcc@gmail.com> writes:
>
> Jonathan> I prefer it as unique_ptr<datum> but I'm probably not your typical
> Jonathan> user of the pretty printers, so if anyone else has an opinion please
> Jonathan> share it.
>
> I prefer it too.  Here's the updated patch.  Let me know what you think.

I like it, please go ahead and check that in it you're happy with it.
Tom Tromey Aug. 15, 2012, 6:39 p.m. UTC | #2
>>>>> "Jonathan" == Jonathan Wakely <jwakely.gcc@gmail.com> writes:

Jonathan> I like it, please go ahead and check that in it you're happy
Jonathan> with it.

I did.  Thanks.

Tom
diff mbox

Patch

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 4520f32..0eac413 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -71,7 +71,9 @@  class UniquePointerPrinter:
         self.val = val
 
     def to_string (self):
-        return self.val['_M_t']
+        v = self.val['_M_t']['_M_head_impl']
+        return ('std::unique_ptr<%s> containing %s' % (str(v.type.target()),
+                                                       str(v)))
 
 class StdListPrinter:
     "Print a std::list"
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
index 54b3275..0d01558 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
@@ -48,6 +48,14 @@  use(const T &container)
     placeholder(*i);
 }
 
+struct datum
+{
+  std::string s;
+  int i;
+};
+
+std::unique_ptr<datum> global;
+
 int
 main()
 {
@@ -86,6 +94,11 @@  main()
   uoms.insert(5);
 // { dg-final { note-test uoms {std::unordered_multiset with 1 elements = {[0] = 5}} } }
 
+  std::unique_ptr<datum> uptr (new datum);
+  uptr->s = "hi bob";
+  uptr->i = 23;
+// { dg-final { regexp-test uptr {std::unique_ptr.datum. containing 0x.*} } }
+
   placeholder(""); // Mark SPOT
   use(efl);
   use(fl);
@@ -93,6 +106,8 @@  main()
   use(eumm);
   use(eus);
   use(eums);
+  use(uoms);
+  use(uptr->s);
 
   return 0;
 }