diff options
author | Markus Böck <markus.boeck02@gmail.com> | 2022-08-06 13:31:48 +0200 |
---|---|---|
committer | Markus Böck <markus.boeck02@gmail.com> | 2022-08-06 14:07:37 +0200 |
commit | f7b73b7e8e6799d566abeb9954a0617e648b833e (patch) | |
tree | a25d2536bf9d0c797b4c433371f2ff0bb3c94af7 | |
parent | 1c5a50e32815a49a41d79ff529ca8611ee49c5c8 (diff) |
[llvm] Remove uses of deprecated `std::iterator`
std::iterator has been deprecated in C++17 and some standard library implementations such as MS STL or libc++ emit deperecation messages when using the class.
Since LLVM has now switched to C++17 these will emit warnings on these implementations, or worse, errors in build configurations using -Werror.
This patch fixes these issues by replacing them with LLVMs own llvm::iterator_facade_base which offers a superset of functionality of std::iterator.
Differential Revision: https://reviews.llvm.org/D131320
-rw-r--r-- | llvm/include/llvm/Transforms/IPO/SampleContextTracker.h | 14 | ||||
-rw-r--r-- | llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h | 9 | ||||
-rw-r--r-- | llvm/unittests/ADT/IteratorTest.cpp | 5 |
3 files changed, 12 insertions, 16 deletions
diff --git a/llvm/include/llvm/Transforms/IPO/SampleContextTracker.h b/llvm/include/llvm/Transforms/IPO/SampleContextTracker.h index a97d5ee3d710..1b1d2ce818f0 100644 --- a/llvm/include/llvm/Transforms/IPO/SampleContextTracker.h +++ b/llvm/include/llvm/Transforms/IPO/SampleContextTracker.h @@ -17,6 +17,7 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator.h" #include "llvm/ProfileData/SampleProf.h" #include <map> #include <queue> @@ -143,8 +144,9 @@ public: return FuncToCtxtProfiles; } - class Iterator : public std::iterator<std::forward_iterator_tag, - const ContextTrieNode *> { + class Iterator : public llvm::iterator_facade_base< + Iterator, std::forward_iterator_tag, ContextTrieNode *, + std::ptrdiff_t, ContextTrieNode **, ContextTrieNode *> { std::queue<ContextTrieNode *> NodeQueue; public: @@ -159,12 +161,6 @@ public: return *this; } - Iterator operator++(int) { - assert(!NodeQueue.empty() && "Iterator already at the end"); - Iterator Ret = *this; - ++(*this); - return Ret; - } bool operator==(const Iterator &Other) const { if (NodeQueue.empty() && Other.NodeQueue.empty()) return true; @@ -172,7 +168,7 @@ public: return false; return NodeQueue.front() == Other.NodeQueue.front(); } - bool operator!=(const Iterator &Other) const { return !(*this == Other); } + ContextTrieNode *operator*() const { assert(!NodeQueue.empty() && "Invalid access to end iterator"); return NodeQueue.front(); diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h index f0c4a86fde78..ccd2482c3fd7 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.h @@ -15,6 +15,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/iterator.h" #include "llvm/ADT/iterator_range.h" #include "llvm/MC/MCInst.h" #include "llvm/Support/MathExtras.h" @@ -41,8 +42,9 @@ public: namespace Hexagon { -class PacketIterator : public std::iterator<std::forward_iterator_tag, - PacketIterator> { +class PacketIterator + : public llvm::iterator_facade_base< + PacketIterator, std::forward_iterator_tag, const MCInst> { MCInstrInfo const &MCII; MCInst::const_iterator BundleCurrent; MCInst::const_iterator BundleEnd; @@ -56,9 +58,6 @@ public: PacketIterator &operator++(); MCInst const &operator*() const; bool operator==(PacketIterator const &Other) const; - bool operator!=(PacketIterator const &Other) const { - return !(*this == Other); - } }; } // end namespace Hexagon diff --git a/llvm/unittests/ADT/IteratorTest.cpp b/llvm/unittests/ADT/IteratorTest.cpp index ba92d00d7d3d..7269bfc4b6fb 100644 --- a/llvm/unittests/ADT/IteratorTest.cpp +++ b/llvm/unittests/ADT/IteratorTest.cpp @@ -19,8 +19,9 @@ namespace { template <int> struct Shadow; -struct WeirdIter : std::iterator<std::input_iterator_tag, Shadow<0>, Shadow<1>, - Shadow<2>, Shadow<3>> {}; +struct WeirdIter + : llvm::iterator_facade_base<WeirdIter, std::input_iterator_tag, Shadow<0>, + Shadow<1>, Shadow<2>, Shadow<3>> {}; struct AdaptedIter : iterator_adaptor_base<AdaptedIter, WeirdIter> {}; |