Make BalsaHeaders::iterator_base and const_header_lines_iterator copy constructor implicit.
The problem I intend to solve is that Envoy fails to compile the assignment in
balsa_headers_test.cc with the message "error: definition of implicit copy
assignment operator for 'iterator_base' is deprecated because it has a
user-provided copy constructor
[-Werror,-Wdeprecated-copy-with-user-provided-copy]". (Unfortunately this does
not reproduce internally by adding -Wdeprecated-copy-with-user-provided-copy to
the BUILD file.)
These two classes (one derived from the other) both have explicit copy
constructors, which apparently implicitly deletes their copy assignment operators.
However, if a class has a copy constructor, it should have a copy assignment
operator as well. The simplest solution to this is to remove the explicit copy
constructor, enabling both the copy constructors and copy assignment operators
to be implicitly defined.
The implementation change here is that `value_` will also be copied. This is
cheap. Also, `value_` is regenerated by Lookup() every time it is accessed, and
the API convention is that previously stored return value of operator*() must
not be accessed anyway after the iterator is mutated, for example, by the copy
assignment operator, so changing `value_` in the (now implicit) copy constructor
and copy assignment operator is safe.
Note that `value_` cannot be removed without removing operator->() and rewriting
all of its call sites (for example, `it->first` to `(*it).first`, which is
ugly).
PiperOrigin-RevId: 446022160
diff --git a/quiche/common/balsa/balsa_headers.h b/quiche/common/balsa/balsa_headers.h
index 38caace..1377e09 100644
--- a/quiche/common/balsa/balsa_headers.h
+++ b/quiche/common/balsa/balsa_headers.h
@@ -1175,13 +1175,8 @@
: public std::iterator<std::forward_iterator_tag,
std::pair<absl::string_view, absl::string_view>> {
public:
- // default constructor.
iterator_base() : headers_(nullptr), idx_(0) {}
- // copy constructor.
- iterator_base(const iterator_base& it)
- : headers_(it.headers_), idx_(it.idx_) {}
-
std::pair<absl::string_view, absl::string_view>& operator*() const {
return Lookup(idx_);
}
@@ -1272,9 +1267,6 @@
public:
const_header_lines_iterator() : iterator_base() {}
- const_header_lines_iterator(const const_header_lines_iterator& it)
- : iterator_base(it.headers_, it.idx_) {}
-
const_header_lines_iterator& operator++() {
iterator_base::increment();
return *this;