From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] More const-correctness in cooked indexer
Date: Fri, 27 Jan 2023 09:22:05 -0700 [thread overview]
Message-ID: <20230127162205.4125816-1-tromey@adacore.com> (raw)
I noticed that iterating over the index yields non-const
cooked_index_entry objects. However, after finalization, they should
not be modified. This patch enforces this by adding const where
needed.
---
gdb/dwarf2/cooked-index.c | 4 ++--
gdb/dwarf2/cooked-index.h | 5 +++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index 09b3fd70b26..bc4fe20aa2a 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -359,7 +359,7 @@ cooked_index::find (const std::string &name, bool completing)
{
wait ();
- auto lower = std::lower_bound (m_entries.begin (), m_entries.end (), name,
+ auto lower = std::lower_bound (m_entries.cbegin (), m_entries.cend (), name,
[=] (const cooked_index_entry *entry,
const std::string &n)
{
@@ -367,7 +367,7 @@ cooked_index::find (const std::string &name, bool completing)
completing);
});
- auto upper = std::upper_bound (m_entries.begin (), m_entries.end (), name,
+ auto upper = std::upper_bound (m_entries.cbegin (), m_entries.cend (), name,
[=] (const std::string &n,
const cooked_index_entry *entry)
{
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index 55eaf9955ab..cb6795b97a7 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -225,13 +225,14 @@ class cooked_index
friend class cooked_index_vector;
/* A simple range over part of m_entries. */
- typedef iterator_range<std::vector<cooked_index_entry *>::iterator> range;
+ typedef iterator_range<std::vector<cooked_index_entry *>::const_iterator>
+ range;
/* Return a range of all the entries. */
range all_entries ()
{
wait ();
- return { m_entries.begin (), m_entries.end () };
+ return { m_entries.cbegin (), m_entries.cend () };
}
/* Look up an entry by name. Returns a range of all matching
--
2.38.1
next reply other threads:[~2023-01-27 16:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-27 16:22 Tom Tromey [this message]
2023-01-27 20:11 ` Simon Marchi
2023-01-27 21:11 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230127162205.4125816-1-tromey@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).