From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 3DDE73858437 for ; Wed, 2 Feb 2022 00:15:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3DDE73858437 Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-673-a_sbke0zP2mefaBcJy8kkw-1; Tue, 01 Feb 2022 19:15:49 -0500 X-MC-Unique: a_sbke0zP2mefaBcJy8kkw-1 Received: by mail-yb1-f199.google.com with SMTP id 127-20020a250f85000000b00611ab6484abso36473290ybp.23 for ; Tue, 01 Feb 2022 16:15:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UiD/KAU7cskZZXhzigCE0lXbfMrhpsd0GYElZoe0UCg=; b=havc3vQxvi22A7i+qukIiRxhb4UDIL4M39lL/q9z3eJKY6cnbIjEmqH1Yr+wj0bH58 4xmsyPBoin3dbz3wNdU60oK4G5kX0gW2gZMlLVAVaUnJBy2Rt3T/sHPFeharlyk7tbAs 7XyRDz3xWYfOXJhKO389sZc1zlU2DrERsFRW9k05R5rtC6ueooYnco/OcnQF5iQYO5ZM MJQBPjcD9va28P0AyowooHRxGugRU8pGkltALhNsj8uoXZ6uVdYbD/xlz+fwBHTZKurn MJlf2tVUtMt0Q5yCHy+bWuSZU+bCaVCUFacof7QV8Y7BOWEZWPgon5NcT/T6KI4Z0BtU hvHg== X-Gm-Message-State: AOAM530easKWSJwEvWujvJPm+Z+/5QhqXF4X+VB8gqtizvxHuLQngoxj SJwXjcjJniF7kTjt444sb08nozXpTCdPVVbeUlDc9kfVDhP76+IBbrTqDNQPQPgRyiz/j3cwxkM OnH+/MYcZFfSG0iwMsAGBQC+T4+n0kNM= X-Received: by 2002:a25:25c4:: with SMTP id l187mr40756830ybl.13.1643760949465; Tue, 01 Feb 2022 16:15:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyAFCbjibMWK/455Zu5EP0RhdAT0BJCiNHWVOi4JIkWgfBsyniOobp16AV+kVxpcHtv0D4BFHsARpOgD6JCbfk= X-Received: by 2002:a25:25c4:: with SMTP id l187mr40756808ybl.13.1643760949254; Tue, 01 Feb 2022 16:15:49 -0800 (PST) MIME-Version: 1.0 References: <2c589ec7-41ec-e581-29ba-1e35825b2d51@gmail.com> In-Reply-To: From: Jonathan Wakely Date: Wed, 2 Feb 2022 00:15:38 +0000 Message-ID: Subject: Re: [PATCH] declare std::array members attribute const [PR101831] To: Martin Sebor Cc: "libstdc++" , gcc-patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Feb 2022 00:15:54 -0000 On Wed, 2 Feb 2022 at 00:13, Martin Sebor wrote: > > On 2/1/22 12:48, Jonathan Wakely wrote: > > On Tue, 1 Feb 2022 at 18:54, Martin Sebor via Libstdc++ > > wrote: > >> > >> Passing an uninitialized object to a function that takes its argument > >> by const reference is diagnosed by -Wmaybe-uninitialized because most > >> such functions read the argument. The exceptions are functions that > >> don't access the object but instead use its address to compute > >> a result. This includes a number of std::array member functions such > >> as std::array::size() which returns the template argument N. Such > >> functions may be candidates for attribute const which also avoids > >> the warning. The attribute typically only benefits extern functions > >> that IPA cannot infer the property from, but in this case it helps > >> avoid the warning which runs very early on, even without optimization > >> or inlining. The attached patch adds the attribute to a subset of > >> those member functions of std::array. (It doesn't add it to const > >> member functions like cbegin() or front() that return a const_iterator > >> or const reference to the internal data.) > >> > >> It might be possible to infer this property from inline functions > >> earlier on than during IPA and avoid having to annotate them explicitly. > >> That seems like an enhancement worth considering in the future. > >> > >> Tested on x86_64-linux. > >> > >> Martin > > > > new file mode 100644 > > index 00000000000..b7743adf3c9 > > --- /dev/null > > +++ b/libstdc++-v3/testsuite/23_containers/array/iterators/begin_end.cc > > @@ -0,0 +1,56 @@ > > +// { dg-do compile { target c++11 } } > > +// > > +// Copyright (C) 2011-2022 Free Software Foundation, Inc. > > > > Those dates look wrong. I no longer bother putting a license text and > > copyright notice on simple tests like this. It's meaningless to assert > > copyright on something so trivial that doesn't do anything. > > > > Should I take to mean that you're okay with the rest of the change > (i.e., with the notice removed)? Yes, OK for trunk either with the notice entirely removed, or just fix the dates (I don't think it is copied from an existing test dating from 2011, right?) Whichever you prefer.