From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Nathan Sidwell <nathan@acm.org>
Cc: Luis Machado <luis.machado@linaro.org>,
"gdb@sourceware.org" <gdb@sourceware.org>,
gcc Mailing List <gcc@gcc.gnu.org>,
Pedro Alves <palves@redhat.com>, Simon Marchi <simark@simark.ca>
Subject: Re: Coding style for C++ constructs going forward
Date: Tue, 11 Aug 2020 16:48:53 +0100 [thread overview]
Message-ID: <CAH6eHdRL9c8h090XhT_+inkME8EZL_SZPDiC43yYakxstXK6Qw@mail.gmail.com> (raw)
In-Reply-To: <e6c5789f-8e1f-732d-76a0-8444e4e8f96b@acm.org>
On Tue, 11 Aug 2020 at 14:56, Nathan Sidwell <nathan@acm.org> wrote:
>
> On 8/7/20 10:06 AM, Luis Machado via Gcc wrote:
> > Hi,
> >
> > cc-ing the GCC mailing list, as we may want to use the same coding style
> > for GDB and GCC.
> >
> > Yesterday I brought this topic up on IRC. I notice we started using more
> > and more the "auto" keyword. In some cases, this is actually useful and
> > makes the code a bit more compact. GDB has been using those more often,
> > whereas GCC, for example, isn't using those too much.
> >
> > Looking at the coding standards for GCC
> > (https://gcc.gnu.org/codingconventions.html), I don't see anything
> > dictating best practices for "auto" use.
> >
> > I guess it is a consensus that "auto" is a good fit when dealing with
> > iterators, lambda's and gnarly templates (but only when the type is
> > already obvious from its use).
> >
> > There are other situations where "auto" may make things a little more
> > cryptic when one wants to figure out the types of the variables. One
> > example of this is when you have a longer function, and you use "auto"
> > in a variable that lives throughout the scope of the function. This
> > means you'll need to go back to its declaration and try to figure out
> > what type this particular variable has.
> >
> > Pedro has pointed out LLVM's coding standards for "auto", which we may
> > or may not want to follow/adopt:
> > https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable
> >
> >
> > It sounds like a reasonable idea to me. Thoughts?
>
> I agree, it's the way I use auto. I particularly like the
> auto *foo = expr;
> idiom, when you're getting a pointer, but the type of the pointee is
> clear. It informs how you use 'foo'.
Yes, great suggestion. I use that in libstdc++ too, e.g.
include/bits/shared_ptr.h: if (auto* __p = dynamic_cast<typename
_Sp::element_type*>(__r.get()))
next prev parent reply other threads:[~2020-08-11 15:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-07 14:06 Luis Machado
2020-08-07 14:56 ` Joel Brobecker
2020-08-07 15:48 ` Jakub Jelinek
2020-08-07 18:21 ` Jonathan Wakely
2020-08-07 19:09 ` Christian Biesinger
2020-08-11 13:55 ` Nathan Sidwell
2020-08-11 15:48 ` Jonathan Wakely [this message]
2020-08-12 2:46 ` Liu Hao
2020-08-12 18:40 ` David Blaikie
2020-08-13 6:44 ` Liu Hao
2020-08-13 8:03 ` 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=CAH6eHdRL9c8h090XhT_+inkME8EZL_SZPDiC43yYakxstXK6Qw@mail.gmail.com \
--to=jwakely.gcc@gmail.com \
--cc=gcc@gcc.gnu.org \
--cc=gdb@sourceware.org \
--cc=luis.machado@linaro.org \
--cc=nathan@acm.org \
--cc=palves@redhat.com \
--cc=simark@simark.ca \
/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