From 7c21cea36f2171672240c78c9c8bcfa365ddf108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Sat, 9 Dec 2023 18:43:38 +0100 Subject: [PATCH] rtlil, hashlib: Remove deprecated `std::iterator` usage `std::iterator` has been deprecated in C++17. Yosys is being compiled against the C++11 standard but plugins can opt to compile against a newer one. To silence some deprecation warnings when those plugins are being compiled, replace the `std::iterator` inheritance with the equivalent type declarations. --- kernel/hashlib.h | 33 ++++++++++++++++++++++++++++----- kernel/rtlil.h | 16 ++++++++++++++-- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/kernel/hashlib.h b/kernel/hashlib.h index 9cf43da6ca5..afee993914e 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -371,7 +371,7 @@ class dict } public: - class const_iterator : public std::iterator> + class const_iterator { friend class dict; protected: @@ -379,6 +379,10 @@ class dict int index; const_iterator(const dict *ptr, int index) : ptr(ptr), index(index) { } public: + typedef std::pair value_type; + typedef ptrdiff_t difference_type; + typedef std::pair* pointer; + typedef std::pair& reference; const_iterator() { } const_iterator operator++() { index--; return *this; } const_iterator operator+=(int amt) { index -= amt; return *this; } @@ -389,7 +393,7 @@ class dict const std::pair *operator->() const { return &ptr->entries[index].udata; } }; - class iterator : public std::iterator> + class iterator { friend class dict; protected: @@ -397,6 +401,11 @@ class dict int index; iterator(dict *ptr, int index) : ptr(ptr), index(index) { } public: + typedef std::forward_iterator_tag iterator_category; + typedef std::pair value_type; + typedef ptrdiff_t difference_type; + typedef std::pair* pointer; + typedef std::pair& reference; iterator() { } iterator operator++() { index--; return *this; } iterator operator+=(int amt) { index -= amt; return *this; } @@ -800,7 +809,7 @@ class pool } public: - class const_iterator : public std::iterator + class const_iterator { friend class pool; protected: @@ -808,6 +817,11 @@ class pool int index; const_iterator(const pool *ptr, int index) : ptr(ptr), index(index) { } public: + typedef std::forward_iterator_tag iterator_category; + typedef K value_type; + typedef ptrdiff_t difference_type; + typedef K* pointer; + typedef K& reference; const_iterator() { } const_iterator operator++() { index--; return *this; } bool operator==(const const_iterator &other) const { return index == other.index; } @@ -816,7 +830,7 @@ class pool const K *operator->() const { return &ptr->entries[index].udata; } }; - class iterator : public std::iterator + class iterator { friend class pool; protected: @@ -824,6 +838,11 @@ class pool int index; iterator(pool *ptr, int index) : ptr(ptr), index(index) { } public: + typedef std::forward_iterator_tag iterator_category; + typedef K value_type; + typedef ptrdiff_t difference_type; + typedef K* pointer; + typedef K& reference; iterator() { } iterator operator++() { index--; return *this; } bool operator==(const iterator &other) const { return index == other.index; } @@ -1021,7 +1040,7 @@ class idict pool database; public: - class const_iterator : public std::iterator + class const_iterator { friend class idict; protected: @@ -1029,6 +1048,10 @@ class idict int index; const_iterator(const idict &container, int index) : container(container), index(index) { } public: + typedef K value_type; + typedef ptrdiff_t difference_type; + typedef K* pointer; + typedef K& reference; const_iterator() { } const_iterator operator++() { index++; return *this; } bool operator==(const const_iterator &other) const { return index == other.index; } diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 17853fae163..9af3d41eca6 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -803,8 +803,14 @@ struct RTLIL::SigBit unsigned int hash() const; }; -struct RTLIL::SigSpecIterator : public std::iterator +struct RTLIL::SigSpecIterator { + typedef std::input_iterator_tag iterator_category; + typedef RTLIL::SigSpec value_type; + typedef ptrdiff_t difference_type; + typedef RTLIL::SigSpec* pointer; + typedef RTLIL::SigSpec& reference; + RTLIL::SigSpec *sig_p; int index; @@ -814,8 +820,14 @@ struct RTLIL::SigSpecIterator : public std::iterator +struct RTLIL::SigSpecConstIterator { + typedef std::input_iterator_tag iterator_category; + typedef RTLIL::SigSpec value_type; + typedef ptrdiff_t difference_type; + typedef RTLIL::SigSpec* pointer; + typedef RTLIL::SigSpec& reference; + const RTLIL::SigSpec *sig_p; int index;