From patchwork Fri Jan 27 16:22:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63796 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 917BE3858C00 for ; Fri, 27 Jan 2023 16:22:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 917BE3858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674836562; bh=d/O75DCwzKj1kQfWuxewRa/tN+6SP6KTpJp27Dyel5c=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ibaofEg+Rhl16upyRYmiYOCoW2N9tqWyaZo/ujSceDiW4XIJm+MbxlBVrZzWQiRAf K9GBCCUJjY2tlv2eUS5tNNjACSqCTdhX5f/HQ8V7IdS6mDYQ/HKDd6DB0BhjcGVzo/ WluT0Op4oLUxst4V+xPIgrx3wrwvGRecdED5y2tI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 0B11E3858C00 for ; Fri, 27 Jan 2023 16:22:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B11E3858C00 Received: by mail-il1-x132.google.com with SMTP id l7so608143ilf.0 for ; Fri, 27 Jan 2023 08:22:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=d/O75DCwzKj1kQfWuxewRa/tN+6SP6KTpJp27Dyel5c=; b=CkCDzwmqoTqiPHSDBuD7u8KDm2oW3k1FfnNkea2QTbCDz00FdgmO8vujKeAlizJR/9 7XiUx5flaVv1sewgT2vHrFCWPlLztLvvqr7Fm9JAugjhI7mgAqJ7n1DA/wki+wuaHThi /mLFFlz+9H7w3FhAZiKbQErNmqt1T2jrmRoI0Rgsa2fBiw6Hi19fqLscXZ0xpCrWBQCm /x1lK0ER3L7bEinCOTM1iFMFI4p//1iqOFjIBXyoWzM9uwRcJa9wvHdeFkMwWY1xLpxr 7IBRpYyXu7JPhHhfA3vOGRWNbidJU4iMdAl9dniSJaU5Pc2m/NoDL4spuxPs7nh7DMhu xQOQ== X-Gm-Message-State: AO0yUKVmWwDXtvyNbBBWWv/I4oy/ud//RrADoW9VQnvoC4eqnaRnG5BZ IM+WwWZ1rablTYqC1YFivWZNXW211F5DjSRM X-Google-Smtp-Source: AK7set/8LLd7dLIyrMAB655bIIbw3agXBPb02tRqCsjkq5csFV7tMVhFFCweWloo1NkyQcpLaZ6rvQ== X-Received: by 2002:a05:6e02:1c4d:b0:310:9ecc:3063 with SMTP id d13-20020a056e021c4d00b003109ecc3063mr12868462ilg.4.1674836536445; Fri, 27 Jan 2023 08:22:16 -0800 (PST) Received: from localhost.localdomain (75-166-146-144.hlrn.qwest.net. [75.166.146.144]) by smtp.gmail.com with ESMTPSA id m14-20020a924a0e000000b0030c68d38255sm1336285ilf.38.2023.01.27.08.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 08:22:15 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] More const-correctness in cooked indexer Date: Fri, 27 Jan 2023 09:22:05 -0700 Message-Id: <20230127162205.4125816-1-tromey@adacore.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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::iterator> range; + typedef iterator_range::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