From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by sourceware.org (Postfix) with ESMTPS id 9B7683857031 for ; Tue, 11 Aug 2020 15:49:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9B7683857031 Received: by mail-il1-x144.google.com with SMTP id p13so11047000ilh.4 for ; Tue, 11 Aug 2020 08:49:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XefCGgU/Rlqj1MDDaYIwt2cT2rwPl0LwMOBNYfOt4YY=; b=G3wnrqL1Tfhsvgsm1uqeFGSqCZp0zW7g96EKEiWFKFcoouud/IX7ikVV0+r9P4PK8a 2x2Iabsm4c3CEe9SUKLO6lFnxkwN8yVvFvEpzf1jZcMZ3DF9ug6P4Ntg2h9hZBKFTbwB 5E5IdpKg9XoI2mdAvhslEF2Z9A/BAckUHosn0NWrp9IrAVmzrKaobGKSMFsnfbbQHGVo eff6tNTric0qKRCUOXWjeKdr+2FfXOtBL2+pjL4beWHSd04DVLGWhZoERgdsbNVj2RlQ tuTxw6dV7Y/Qm8ucAFpY9ns8KE0/b30ucb+v34OHJDmsQZh+MHoNtEwuqZIyAxEXax8q JtOA== X-Gm-Message-State: AOAM530RxqqCni8Ge6O4rdbeVjAd4lNGjfr5pEuwwafAwr6fiyNX3cDU nOErqsu2NLNTafynBPR4oiWHx5UoG4YLDgBYZoQ= X-Google-Smtp-Source: ABdhPJx9Fja+1JAgpnDaDVpgkXyc8nqWzUoknU/87hUrKmwESWf+wx7BB3JJWF/ZvR9ALHEIVha9aaiTftGjn2xF72w= X-Received: by 2002:a92:d7ca:: with SMTP id g10mr3499079ilq.30.1597160944077; Tue, 11 Aug 2020 08:49:04 -0700 (PDT) MIME-Version: 1.0 References: <33412819-8a5e-0c7f-7cfb-f3d127dc2242@linaro.org> In-Reply-To: From: Jonathan Wakely Date: Tue, 11 Aug 2020 16:48:53 +0100 Message-ID: Subject: Re: Coding style for C++ constructs going forward To: Nathan Sidwell Cc: Luis Machado , "gdb@sourceware.org" , gcc Mailing List , Pedro Alves , Simon Marchi Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Aug 2020 15:49:06 -0000 On Tue, 11 Aug 2020 at 14:56, Nathan Sidwell 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(__r.get()))