From: Martin Sebor <msebor@gmail.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: libstdc++ <libstdc++@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] declare std::array members attribute const [PR101831]
Date: Tue, 1 Feb 2022 17:13:47 -0700 [thread overview]
Message-ID: <b4c38462-bf64-0def-52a5-894cace23fef@gmail.com> (raw)
In-Reply-To: <CACb0b4nRD5PsQrYuSKJyXmPJVDrrYiZ-nAw2noVQJU2y=inVtw@mail.gmail.com>
On 2/1/22 12:48, Jonathan Wakely wrote:
> On Tue, 1 Feb 2022 at 18:54, Martin Sebor via Libstdc++
> <libstdc++@gcc.gnu.org> 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<N>::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)?
Martin
next prev parent reply other threads:[~2022-02-02 0:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-01 18:53 Martin Sebor
2022-02-01 19:48 ` Jonathan Wakely
2022-02-02 0:13 ` Martin Sebor [this message]
2022-02-02 0:15 ` Jonathan Wakely
2022-02-02 0:23 ` Martin Sebor
2022-02-02 9:15 ` Jonathan Wakely
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=b4c38462-bf64-0def-52a5-894cace23fef@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jwakely@redhat.com \
--cc=libstdc++@gcc.gnu.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).