diff mbox

libstdc++: Fix libstdc++/67440: pretty-printing of a const set<foo> fails

Message ID 047d7b10cdcf8731080524aec2e9@google.com
State New
Headers show

Commit Message

Doug Evans Nov. 16, 2015, 9:04 p.m. UTC
Hi.

Apologies for the delay.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67440

Tested with current trunk.

2015-11-16  Doug Evans  <dje@google.com>

	PR libstdc++/67440
	* python/libstdcxx/v6/printers.py (find_type): Handle "const" in
	type name.
	* testsuite/libstdc++-prettyprinters/debug.cc: Add test for
	const set<int>.
	* testsuite/libstdc++-prettyprinters/simple.cc: Ditto.
	* testsuite/libstdc++-prettyprinters/simple11.cc: Ditto.

    sp.insert("barrel");

Comments

Jonathan Wakely Nov. 16, 2015, 9:24 p.m. UTC | #1
On 16/11/15 21:04 +0000, Doug Evans wrote:
>Hi.
>
>Apologies for the delay.
>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67440
>
>Tested with current trunk.
>
>2015-11-16  Doug Evans  <dje@google.com>
>
>	PR libstdc++/67440
>	* python/libstdcxx/v6/printers.py (find_type): Handle "const" in
>	type name.
>	* testsuite/libstdc++-prettyprinters/debug.cc: Add test for
>	const set<int>.
>	* testsuite/libstdc++-prettyprinters/simple.cc: Ditto.
>	* testsuite/libstdc++-prettyprinters/simple11.cc: Ditto.
>
>Index: python/libstdcxx/v6/printers.py
>===================================================================
>--- python/libstdcxx/v6/printers.py	(revision 227421)
>+++ python/libstdcxx/v6/printers.py	(working copy)
>@@ -85,7 +85,9 @@
> def find_type(orig, name):
>     typ = orig.strip_typedefs()
>     while True:
>-        search = str(typ) + '::' + name
>+        # Use typ.name here instead of str(typ) to discard any const,etc.
>+        # qualifiers.  PR 67440.
>+        search = typ.name + '::' + name

Oh, that's surprisingly simple! :-)

This only affects the printers, so although we're in stage 3 this is
OK for trunk and gcc-5-branch, thanks.
Alan Lawrence Nov. 25, 2015, 5:29 p.m. UTC | #2
On 16/11/15 21:04, Doug Evans wrote:
> Hi.
>
> Apologies for the delay.
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67440
>
> Tested with current trunk.
>
> 2015-11-16  Doug Evans  <dje@google.com>
>
>      PR libstdc++/67440
>      * python/libstdcxx/v6/printers.py (find_type): Handle "const" in
>      type name.
>      * testsuite/libstdc++-prettyprinters/debug.cc: Add test for
>      const set<int>.
>      * testsuite/libstdc++-prettyprinters/simple.cc: Ditto.
>      * testsuite/libstdc++-prettyprinters/simple11.cc: Ditto.

On gcc-5-branch, the debug.cc and simple.cc tests don't seem to compile, on 
either x86_64-none-linux-gnu or aarch64-none-linux-gnu. I get errors like:

/work/alalaw01/src/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc: In 
function 'int main()':
/work/alalaw01/src/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc:77:43: 
error: in C++98 'const_intset' must be initialized by constructor, not by '{...}'
    const std::set<int> const_intset = {2, 3};
                                            ^
In file included from 
/work/alalaw01/build_dje/x86_64-unknown-linux-gnu/libstdc++-v3/include/map:60:0,
                  from 
/work/alalaw01/src/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc:31:
/work/alalaw01/build_dje/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/stl_tree.h: 
In instantiation of 'void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, 
_Alloc>::_M_insert_unique(_II, _II) [with _InputIterator = int; _Key = int; _Val 
= int; _KeyOfValue = std::_Identity<int>; _Compare = std::less<int>; _Alloc = 
std::allocator<int>]':
/work/alalaw01/build_dje/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/stl_set.h:171:4: 
   required from 'std::set<_Key, _Compare, _Alloc>::set(_InputIterator, 
_InputIterator) [with _InputIterator = int; _Key = int; _Compare = 
std::less<int>; _Alloc = std::allocator<int>]'
/work/alalaw01/src/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc:77:43: 
   required from here
/work/alalaw01/build_dje/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/stl_tree.h:2224:29: 
error: invalid type argument of unary '*' (have 'int')
     _M_insert_unique_(end(), *__first, __an);
                              ^
compiler exited with status 1
UNRESOLVED: libstdc++-prettyprinters/simple.cc compilation failed to produce 
executable
Spawning: gdb -nw -nx -quiet -batch -ex "python print(gdb.type_printers)"
spawn gdb -nw -nx -quiet -batch -ex python print(gdb.type_printers)
[]
spawn gdb -nx -nw -quiet -batch -x simple.gdb
simple.gdb:2: Error in sourced command file:
./simple.exe: No such file or directory.
skipping: simple.gdb:2: Error in sourced command file:
skipping: ./simple.exe: No such file or directory.
UNSUPPORTED: libstdc++-prettyprinters/simple.cc

I also see signs of the same on powerpc64le 
(https://gcc.gnu.org/ml/gcc-testresults/2015-11/msg02699.html), the test looks 
to be passing on trunk on all three platforms.

Thanks, Alan
Jonathan Wakely Nov. 25, 2015, 7:55 p.m. UTC | #3
On 25 November 2015 at 17:29, Alan Lawrence <alan.lawrence@arm.com> wrote:
> On 16/11/15 21:04, Doug Evans wrote:
>>
>> Hi.
>>
>> Apologies for the delay.
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67440
>>
>> Tested with current trunk.
>>
>> 2015-11-16  Doug Evans  <dje@google.com>
>>
>>      PR libstdc++/67440
>>      * python/libstdcxx/v6/printers.py (find_type): Handle "const" in
>>      type name.
>>      * testsuite/libstdc++-prettyprinters/debug.cc: Add test for
>>      const set<int>.
>>      * testsuite/libstdc++-prettyprinters/simple.cc: Ditto.
>>      * testsuite/libstdc++-prettyprinters/simple11.cc: Ditto.
>
>
> On gcc-5-branch, the debug.cc and simple.cc tests don't seem to compile, on
> either x86_64-none-linux-gnu or aarch64-none-linux-gnu. I get errors like:
>
> /work/alalaw01/src/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc:
> In function 'int main()':
> /work/alalaw01/src/gcc/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc:77:43:
> error: in C++98 'const_intset' must be initialized by constructor, not by
> '{...}'
>    const std::set<int> const_intset = {2, 3};
>                                            ^

Which should have failed to compile on trunk as well, but we're
missing a -std=gnu++98 in the simple.cc testcase, so on trunk it uses
the -std=gnu++14 default. I'll add -std=gnu++98 to the test.
diff mbox

Patch

Index: python/libstdcxx/v6/printers.py
===================================================================
--- python/libstdcxx/v6/printers.py	(revision 227421)
+++ python/libstdcxx/v6/printers.py	(working copy)
@@ -85,7 +85,9 @@ 
  def find_type(orig, name):
      typ = orig.strip_typedefs()
      while True:
-        search = str(typ) + '::' + name
+        # Use typ.name here instead of str(typ) to discard any const,etc.
+        # qualifiers.  PR 67440.
+        search = typ.name + '::' + name
          try:
              return gdb.lookup_type(search)
          except RuntimeError:
Index: testsuite/libstdc++-prettyprinters/debug.cc
===================================================================
--- testsuite/libstdc++-prettyprinters/debug.cc	(revision 227421)
+++ testsuite/libstdc++-prettyprinters/debug.cc	(working copy)
@@ -70,6 +70,10 @@ 
    std::map<std::string, int>::iterator mpiter = mp.begin();
  // { dg-final { note-test mpiter {{first = "zardoz", second = 23}} } }

+  // PR 67440
+  const std::set<int> const_intset = {2, 3};
+// { dg-final { note-test const_intset {std::__debug::set with 2 elements  
= {[0] = 2, [1] = 3}} } }
+
    std::set<std::string> sp;
    sp.insert("clownfish");
    sp.insert("barrel");
Index: testsuite/libstdc++-prettyprinters/simple.cc
===================================================================
--- testsuite/libstdc++-prettyprinters/simple.cc	(revision 227421)
+++ testsuite/libstdc++-prettyprinters/simple.cc	(working copy)
@@ -73,6 +73,10 @@ 
    std::map<std::string, int>::iterator mpiter = mp.begin();
  // { dg-final { note-test mpiter {{first = "zardoz", second = 23}} } }

+  // PR 67440
+  const std::set<int> const_intset = {2, 3};
+// { dg-final { note-test const_intset {std::set with 2 elements = {[0] =  
2, [1] = 3}} } }
+
    std::set<std::string> sp;
    sp.insert("clownfish");
    sp.insert("barrel");
Index: testsuite/libstdc++-prettyprinters/simple11.cc
===================================================================
--- testsuite/libstdc++-prettyprinters/simple11.cc	(revision 227421)
+++ testsuite/libstdc++-prettyprinters/simple11.cc	(working copy)
@@ -73,6 +73,10 @@ 
    std::map<std::string, int>::iterator mpiter = mp.begin();
  // { dg-final { note-test mpiter {{first = "zardoz", second = 23}} } }

+  // PR 67440
+  const std::set<int> const_intset = {2, 3};
+// { dg-final { note-test const_intset {std::set with 2 elements = {[0] =  
2, [1] = 3}} } }
+
    std::set<std::string> sp;
    sp.insert("clownfish");