From: Jonathan Wakely <jwakely@redhat.com>
To: Martin Sebor <msebor@gmail.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 19:48:47 +0000 [thread overview]
Message-ID: <CACb0b4nRD5PsQrYuSKJyXmPJVDrrYiZ-nAw2noVQJU2y=inVtw@mail.gmail.com> (raw)
In-Reply-To: <2c589ec7-41ec-e581-29ba-1e35825b2d51@gmail.com>
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.
next prev parent reply other threads:[~2022-02-01 19:48 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 [this message]
2022-02-02 0:13 ` Martin Sebor
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='CACb0b4nRD5PsQrYuSKJyXmPJVDrrYiZ-nAw2noVQJU2y=inVtw@mail.gmail.com' \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=msebor@gmail.com \
/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).