From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by sourceware.org (Postfix) with ESMTPS id E22BD3857C55 for ; Fri, 7 Aug 2020 19:10:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E22BD3857C55 Received: by mail-qk1-x72c.google.com with SMTP id b14so2707723qkn.4 for ; Fri, 07 Aug 2020 12:10:01 -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=Njd08vYKKu8H9kM4ihTZeYbCuZy9qrDQCVbjQYzisKI=; b=I+TE8ri1cwr3nyl2GHsn1/IskWEqluuIGIO7CsgEL/Ga5IhotrJB6BGlgOfOIkupIo /jN9J/JUlkUj9pWu4Kz4OWcdXK6XX+xt+OOWBp2KyrddHPRKjcTpLBWz5h2CkbBw9nvw 8Za2qi/fgVDUkcrQwuwhQkfVjsMV5NXp8wn+h6BqsKpLGLTuETPyhY7dE8e+C3lGJOc6 EbOZ0rJbqPztrDKjf8Tn5PvVRWgn4umXFKQzog9XrkobhA+9vHybWI0sbL+fQLXZ0Nol /+JR33S+CwtWxWlrIjZnMat5lNvRaAMCBpZaObJ/Rx4S5HT9n93G6T5cr15ERuPJh1OE SL7A== X-Gm-Message-State: AOAM532M35GXtg8rrnj9Cs63Xg6mNaw2INo6pI3ki0nps70op6oEBAgz kW+0f7WeUV9hSBHlGfhdYKbetMkfIDpWN0H1K2uMuXLU X-Google-Smtp-Source: ABdhPJz2Qq96W5+V6QgZsCtSVx8VBJ42ktzsMyb3JnN7qIVGIFGadaeb6Ciy8RzHmEGPyMfdSJnfRel4kIfG/l+3Trc= X-Received: by 2002:a37:a851:: with SMTP id r78mr14896997qke.419.1596827401044; Fri, 07 Aug 2020 12:10:01 -0700 (PDT) MIME-Version: 1.0 References: <33412819-8a5e-0c7f-7cfb-f3d127dc2242@linaro.org> In-Reply-To: <33412819-8a5e-0c7f-7cfb-f3d127dc2242@linaro.org> From: Christian Biesinger Date: Fri, 7 Aug 2020 14:09:24 -0500 Message-ID: Subject: Re: Coding style for C++ constructs going forward To: Luis Machado Cc: "gdb@sourceware.org" , gcc Mailing List , Pedro Alves , Simon Marchi Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-18.8 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham 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: Fri, 07 Aug 2020 19:10:03 -0000 On Fri, Aug 7, 2020 at 9:06 AM Luis Machado via Gdb 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? The LLVM guide seems pretty similar to what the Google C++ guide *used* to say, which was basically "You can use auto for iterators and when the type is explicit on the initializer, e.g. for auto* x = new Foo()". I liked that rule. (The new version says "Use it if it makes the code more readable" with no detailed guidance, which makes me sad) Christian