Andrew Geissler | 8f84068 | 2023-07-21 09:09:43 -0500 | [diff] [blame^] | 1 | From 787d5052a6034cc722b073c652cc610ae037f933 Mon Sep 17 00:00:00 2001 |
| 2 | From: Levi Tamasi <ltamasi@fb.com> |
| 3 | Date: Fri, 22 Nov 2019 18:12:35 -0800 |
| 4 | Subject: [PATCH 1/2] Fix the constness issues around |
| 5 | autovector::iterator_impl's dereference operators (#6057) |
| 6 | |
| 7 | Summary: |
| 8 | As described in detail in issue https://github.com/facebook/rocksdb/issues/6048, iterators' dereference operators |
| 9 | (`*`, `->`, and `[]`) should return `pointer`s/`reference`s (as opposed to |
| 10 | `const_pointer`s/`const_reference`s) even if the iterator itself is `const` |
| 11 | to be in sync with the standard's iterator concept. |
| 12 | Pull Request resolved: https://github.com/facebook/rocksdb/pull/6057 |
| 13 | |
| 14 | Test Plan: make check |
| 15 | |
| 16 | Differential Revision: D18623235 |
| 17 | |
| 18 | Pulled By: ltamasi |
| 19 | |
| 20 | fbshipit-source-id: 04e82d73bc0c67fb0ded018383af8dfc332050cc |
| 21 | --- |
| 22 | thirdparty/rocksdb/util/autovector.h | 15 ++++----------- |
| 23 | 1 file changed, 4 insertions(+), 11 deletions(-) |
| 24 | |
| 25 | diff --git a/thirdparty/rocksdb/util/autovector.h b/thirdparty/rocksdb/util/autovector.h |
| 26 | index b5c84712..6d337908 100644 |
| 27 | --- a/thirdparty/rocksdb/util/autovector.h |
| 28 | +++ b/thirdparty/rocksdb/util/autovector.h |
| 29 | @@ -120,27 +120,20 @@ class autovector { |
| 30 | } |
| 31 | |
| 32 | // -- Reference |
| 33 | - reference operator*() { |
| 34 | + reference operator*() const { |
| 35 | assert(vect_->size() >= index_); |
| 36 | return (*vect_)[index_]; |
| 37 | } |
| 38 | |
| 39 | - const_reference operator*() const { |
| 40 | - assert(vect_->size() >= index_); |
| 41 | - return (*vect_)[index_]; |
| 42 | - } |
| 43 | - |
| 44 | - pointer operator->() { |
| 45 | + pointer operator->() const { |
| 46 | assert(vect_->size() >= index_); |
| 47 | return &(*vect_)[index_]; |
| 48 | } |
| 49 | |
| 50 | - const_pointer operator->() const { |
| 51 | - assert(vect_->size() >= index_); |
| 52 | - return &(*vect_)[index_]; |
| 53 | + reference operator[](difference_type len) const { |
| 54 | + return *(*this + len); |
| 55 | } |
| 56 | |
| 57 | - |
| 58 | // -- Logical Operators |
| 59 | bool operator==(const self_type& other) const { |
| 60 | assert(vect_ == other.vect_); |
| 61 | -- |
| 62 | 2.41.0 |
| 63 | |