summaryrefslogtreecommitdiff
path: root/compiler/optimizing/nodes.h
diff options
context:
space:
mode:
author Ryan Prichard <rprichard@google.com> 2023-09-01 02:07:15 -0700
committer Ryan Prichard <rprichard@google.com> 2023-09-08 23:54:07 +0000
commit743ce223c81f33f2955c64f39f85ca6c64099cb7 (patch)
tree599a9888434fcf757fd64af72187adb5bf6efbbb /compiler/optimizing/nodes.h
parent5899d7919d5ad8e0c437e72c4aa04d4024e32431 (diff)
Stop inheriting from std::iterator
std::iterator was deprecated in C++17 and after upgrading libc++, the compiler warns about the many uses of it in ART. p0174r1 gives a couple of reasons for its deprecation: "The long sequence of void arguments is much less clear to the reader than simply providing the expected typedefs in the class definition itself, which is the approach taken by the current working draft, ... "In addition to the reduced clarity, the iterator template also lays a trap for the unwary, as in typical usage it will be a dependent base class, which means it will not be looking into during name lookup from within the class or its member functions." The first reason is illustrated by the comments in BitTable::const_iterator. The second reason is illustrated by the various "using foo = typename std::iterator<...>::foo" declarations. Follow p0174r1's advice and simply provide the 5 typedefs in each iterator class. Bug: b/175635923 Test: treehugger Change-Id: I2fba5af68eb05fd0a8ba5e2add0c8b8ed1ebee1a
Diffstat (limited to 'compiler/optimizing/nodes.h')
-rw-r--r--compiler/optimizing/nodes.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index 1ad11d80a5..a44e349b4d 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -2194,9 +2194,14 @@ class HEnvironment : public ArenaObject<kArenaAllocEnvironment> {
std::ostream& operator<<(std::ostream& os, const HInstruction& rhs);
// Iterates over the Environments
-class HEnvironmentIterator : public ValueObject,
- public std::iterator<std::forward_iterator_tag, HEnvironment*> {
+class HEnvironmentIterator : public ValueObject {
public:
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = HEnvironment*;
+ using difference_type = ptrdiff_t;
+ using pointer = value_type*;
+ using reference = value_type&;
+
explicit HEnvironmentIterator(HEnvironment* cur) : cur_(cur) {}
HEnvironment* operator*() const {
@@ -2915,9 +2920,14 @@ class HBackwardInstructionIterator : public ValueObject {
};
template <typename InnerIter>
-struct HSTLInstructionIterator : public ValueObject,
- public std::iterator<std::forward_iterator_tag, HInstruction*> {
+struct HSTLInstructionIterator : public ValueObject {
public:
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = HInstruction*;
+ using difference_type = ptrdiff_t;
+ using pointer = value_type*;
+ using reference = value_type&;
+
static_assert(std::is_same_v<InnerIter, HBackwardInstructionIterator> ||
std::is_same_v<InnerIter, HInstructionIterator> ||
std::is_same_v<InnerIter, HInstructionIteratorHandleChanges>,