mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-01-19 18:54:42 +08:00
PR59170 make pretty printers check for singular iterators
PR libstdc++/59170 * python/libstdcxx/v6/printers.py (StdListIteratorPrinter.to_string) (StdSlistIteratorPrinter.to_string, StdVectorIteratorPrinter.to_string) (StdRbtreeIteratorPrinter.to_string) (StdDequeIteratorPrinter.to_string): Add check for value-initialized iterators. * testsuite/libstdc++-prettyprinters/simple.cc: Test them. * testsuite/libstdc++-prettyprinters/simple11.cc: Likewise. From-SVN: r243692
This commit is contained in:
parent
fec5ce2485
commit
bdfc9f5c54
@ -1,5 +1,14 @@
|
||||
2016-12-15 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
PR libstdc++/59170
|
||||
* python/libstdcxx/v6/printers.py (StdListIteratorPrinter.to_string)
|
||||
(StdSlistIteratorPrinter.to_string, StdVectorIteratorPrinter.to_string)
|
||||
(StdRbtreeIteratorPrinter.to_string)
|
||||
(StdDequeIteratorPrinter.to_string): Add check for value-initialized
|
||||
iterators.
|
||||
* testsuite/libstdc++-prettyprinters/simple.cc: Test them.
|
||||
* testsuite/libstdc++-prettyprinters/simple11.cc: Likewise.
|
||||
|
||||
PR libstdc++/59161
|
||||
* python/libstdcxx/v6/printers.py (StdListIteratorPrinter.to_string)
|
||||
(StdSlistIteratorPrinter.to_string, StdVectorIteratorPrinter.to_string)
|
||||
|
@ -200,6 +200,8 @@ class StdListIteratorPrinter:
|
||||
self.typename = typename
|
||||
|
||||
def to_string(self):
|
||||
if not self.val['_M_node']:
|
||||
return 'non-dereferenceable iterator for std::list'
|
||||
nodetype = find_type(self.val.type, '_Node')
|
||||
nodetype = nodetype.strip_typedefs().pointer()
|
||||
node = self.val['_M_node'].cast(nodetype).dereference()
|
||||
@ -246,6 +248,8 @@ class StdSlistIteratorPrinter:
|
||||
self.val = val
|
||||
|
||||
def to_string(self):
|
||||
if not self.val['_M_node']:
|
||||
return 'non-dereferenceable iterator for __gnu_cxx::slist'
|
||||
nodetype = find_type(self.val.type, '_Node')
|
||||
nodetype = nodetype.strip_typedefs().pointer()
|
||||
return str(self.val['_M_node'].cast(nodetype).dereference()['_M_data'])
|
||||
@ -333,6 +337,8 @@ class StdVectorIteratorPrinter:
|
||||
self.val = val
|
||||
|
||||
def to_string(self):
|
||||
if not self.val['_M_current']:
|
||||
return 'non-dereferenceable iterator for std::vector'
|
||||
return str(self.val['_M_current'].dereference())
|
||||
|
||||
class StdTuplePrinter:
|
||||
@ -494,6 +500,8 @@ class StdRbtreeIteratorPrinter:
|
||||
self.link_type = nodetype.strip_typedefs().pointer()
|
||||
|
||||
def to_string (self):
|
||||
if not self.val['_M_node']:
|
||||
return 'non-dereferenceable iterator for associative container'
|
||||
node = self.val['_M_node'].cast(self.link_type).dereference()
|
||||
return str(get_value_from_Rb_tree_node(node))
|
||||
|
||||
@ -708,6 +716,8 @@ class StdDequeIteratorPrinter:
|
||||
self.val = val
|
||||
|
||||
def to_string(self):
|
||||
if not self.val['_M_cur']:
|
||||
return 'non-dereferenceable iterator for std::deque'
|
||||
return str(self.val['_M_cur'].dereference())
|
||||
|
||||
class StdStringPrinter:
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <ext/slist>
|
||||
|
||||
int
|
||||
@ -50,6 +51,9 @@ main()
|
||||
deq.push_back("two");
|
||||
// { dg-final { note-test deq {std::deque with 2 elements = {"one", "two"}} } }
|
||||
|
||||
std::deque<int>::iterator deqiter0;
|
||||
// { dg-final { note-test deqiter0 {non-dereferenceable iterator for std::deque} } }
|
||||
|
||||
std::deque<std::string>::iterator deqiter = deq.begin();
|
||||
// { dg-final { note-test deqiter {"one"} } }
|
||||
|
||||
@ -58,6 +62,9 @@ main()
|
||||
lst.push_back("two");
|
||||
// { dg-final { note-test lst {std::list = {[0] = "one", [1] = "two"}} } }
|
||||
|
||||
std::list<int>::iterator lstiter0;
|
||||
// { dg-final { note-test lstiter0 {non-dereferenceable iterator for std::list} } }
|
||||
|
||||
std::list<std::string>::iterator lstiter = lst.begin();
|
||||
tem = *lstiter;
|
||||
// { dg-final { note-test lstiter {"one"}} }
|
||||
@ -73,6 +80,9 @@ main()
|
||||
std::map<std::string, int>::iterator mpiter = mp.begin();
|
||||
// { dg-final { note-test mpiter {{first = "zardoz", second = 23}} } }
|
||||
|
||||
std::map<std::string, int>::iterator mpiter0;
|
||||
// { dg-final { note-test mpiter0 {non-dereferenceable iterator for associative container} } }
|
||||
|
||||
// PR 67440
|
||||
std::set<int> intset;
|
||||
intset.insert(2);
|
||||
@ -88,6 +98,20 @@ main()
|
||||
std::set<std::string>::const_iterator spciter = sp.begin();
|
||||
// { dg-final { note-test spciter {"barrel"} } }
|
||||
|
||||
std::set<int>::iterator spiter0;
|
||||
// { dg-final { note-test spiter0 {non-dereferenceable iterator for associative container} } }
|
||||
|
||||
std::vector<int> v;
|
||||
v.push_back(1);
|
||||
v.push_back(2);
|
||||
v.erase(v.begin());
|
||||
// { dg-final { note-test v {std::vector of length 1, capacity 2 = {2}} } }
|
||||
std::vector<int>::iterator viter3 = v.begin();
|
||||
// { dg-final { note-test viter3 {2} } }
|
||||
|
||||
std::vector<int>::iterator viter0;
|
||||
// { dg-final { note-test viter0 {non-dereferenceable iterator for std::vector} } }
|
||||
|
||||
__gnu_cxx::slist<int> sll;
|
||||
sll.push_front(23);
|
||||
sll.push_front(47);
|
||||
@ -96,6 +120,9 @@ main()
|
||||
__gnu_cxx::slist<int>::iterator slliter = sll.begin();
|
||||
// { dg-final { note-test slliter {47} } }
|
||||
|
||||
__gnu_cxx::slist<int>::iterator slliter0;
|
||||
// { dg-final { note-test slliter0 {non-dereferenceable iterator for __gnu_cxx::slist} } }
|
||||
|
||||
std::cout << "\n";
|
||||
return 0; // Mark SPOT
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <ext/slist>
|
||||
|
||||
int
|
||||
@ -53,6 +54,9 @@ main()
|
||||
std::deque<std::string>::iterator deqiter = deq.begin();
|
||||
// { dg-final { note-test deqiter {"one"} } }
|
||||
|
||||
std::deque<int>::iterator deqiter0;
|
||||
// { dg-final { note-test deqiter0 {non-dereferenceable iterator for std::deque} } }
|
||||
|
||||
std::list<std::string> lst;
|
||||
lst.push_back("one");
|
||||
lst.push_back("two");
|
||||
@ -66,6 +70,9 @@ main()
|
||||
tem = *lstciter;
|
||||
// { dg-final { note-test lstciter {"one"}} }
|
||||
|
||||
std::list<int>::iterator lstiter0;
|
||||
// { dg-final { note-test lstiter0 {non-dereferenceable iterator for std::list} } }
|
||||
|
||||
std::map<std::string, int> mp;
|
||||
mp["zardoz"] = 23;
|
||||
// { dg-final { note-test mp {std::map with 1 element = {["zardoz"] = 23}} } }
|
||||
@ -73,6 +80,9 @@ main()
|
||||
std::map<std::string, int>::iterator mpiter = mp.begin();
|
||||
// { dg-final { note-test mpiter {{first = "zardoz", second = 23}} } }
|
||||
|
||||
std::map<std::string, int>::iterator mpiter0;
|
||||
// { dg-final { note-test mpiter0 {non-dereferenceable iterator for associative container} } }
|
||||
|
||||
// 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}} } }
|
||||
@ -85,6 +95,20 @@ main()
|
||||
std::set<std::string>::const_iterator spciter = sp.begin();
|
||||
// { dg-final { note-test spciter {"barrel"} } }
|
||||
|
||||
std::set<int>::iterator spiter0;
|
||||
// { dg-final { note-test spiter0 {non-dereferenceable iterator for associative container} } }
|
||||
|
||||
std::vector<int> v;
|
||||
v.push_back(1);
|
||||
v.push_back(2);
|
||||
v.erase(v.begin());
|
||||
// { dg-final { note-test v {std::vector of length 1, capacity 2 = {2}} } }
|
||||
std::vector<int>::iterator viter3 = v.begin();
|
||||
// { dg-final { note-test viter3 {2} } }
|
||||
|
||||
std::vector<int>::iterator viter0;
|
||||
// { dg-final { note-test viter0 {non-dereferenceable iterator for std::vector} } }
|
||||
|
||||
__gnu_cxx::slist<int> sll;
|
||||
sll.push_front(23);
|
||||
sll.push_front(47);
|
||||
@ -93,6 +117,9 @@ main()
|
||||
__gnu_cxx::slist<int>::iterator slliter = sll.begin();
|
||||
// { dg-final { note-test slliter {47} } }
|
||||
|
||||
__gnu_cxx::slist<int>::iterator slliter0;
|
||||
// { dg-final { note-test slliter0 {non-dereferenceable iterator for __gnu_cxx::slist} } }
|
||||
|
||||
std::cout << "\n";
|
||||
return 0; // Mark SPOT
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user