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 1EB603857C47 for ; Wed, 2 Feb 2022 09:15:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1EB603857C47 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-221-qWSLyToXOgakibkGcIN-8Q-1; Wed, 02 Feb 2022 04:15:28 -0500 X-MC-Unique: qWSLyToXOgakibkGcIN-8Q-1 Received: by mail-yb1-f199.google.com with SMTP id a125-20020a25ca83000000b00619442ade1cso29602302ybg.1 for ; Wed, 02 Feb 2022 01:15:28 -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=rCOvIJ6PbB4hKPMCTgDgPqAtDF01FV9+OF3NkxecrS8=; b=QnrnwJ9bLNZAsQHxaTxHgDV3LUzFNO4O5LqGHtl4EXl+tGb9ZkJq0zZWdpF0QBrXLv utRK1hnk+2zrCQ767vWXf3mlNbgUMPSJEuyVx6BOSePOpZmY4OGTFcqx50PLF0EaA74o WxAKZxz5TvULnEe1bN9Vd9H0q00WJgRNKJ9wSrMHzIHDRgU7xgJ4V+UkmnhUwF07rFAu 48Rtw7EtWDe03xjPGtoS2NthIIhVW+trekeCLscl/99b1oS6CYmPudDC+CoHzCrFiMIG 5zc0qL4YQwdUC8arpvMXY1NiheZwqZn+wF36mz2ETzqmpbeeAFr0/Xdb9owFgok1eXPp fqvw== X-Gm-Message-State: AOAM532ZSqrZcrXXbBRru2eSuoKE7gRIYOfXeLcyBfZx1VsScjRstWKR lIIGE+od9YRYtcDdfA8OSrdzDKahCYncPeo6wDauXXt4n0Lut4jPZSdYDGA5P87U89h5vafvUsn AaRRy8/bm/9jVOruNRbUHsZm1le7jd2E= X-Received: by 2002:a05:6902:12cc:: with SMTP id j12mr35157293ybu.580.1643793328041; Wed, 02 Feb 2022 01:15:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJz70sE1oS5qjEPJVPi0WjhWqiVB/Q72huuAXCAisLgLVlUSmV4nOtRUwlfPRvpS28QI2ByuitoQrMp/aOr2OFU= X-Received: by 2002:a05:6902:12cc:: with SMTP id j12mr35157279ybu.580.1643793327833; Wed, 02 Feb 2022 01:15:27 -0800 (PST) MIME-Version: 1.0 References: <2c589ec7-41ec-e581-29ba-1e35825b2d51@gmail.com> <12955ecf-586a-742c-ce9a-b3de11c52079@gmail.com> In-Reply-To: <12955ecf-586a-742c-ce9a-b3de11c52079@gmail.com> From: Jonathan Wakely Date: Wed, 2 Feb 2022 09:15:16 +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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 09:15:32 -0000 On Wed, 2 Feb 2022 at 00:23, Martin Sebor wrote: > > On 2/1/22 17:15, Jonathan Wakely wrote: > > 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?) > > I copied it from 23_containers/array/iterators/end_is_one_past.cc > without even looking at the dates. Yeah, we all do that, and we all forget to fix the dates. It's just one more reason not to bother putting 16 lines of licence notices in tests, when the notice is often bigger than the test itself! > > > > > Whichever you prefer. > > > > Okay, pushed in r12-6992. Thanks.