Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3162077pxm; Mon, 28 Feb 2022 13:25:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaOWPSUuYR1Uy0Qwek4BkOwefyaLGB46GFIvqFbEpbK+qxhv6LejWK4+iFByf2/iMFeN1R X-Received: by 2002:a05:6402:90b:b0:412:a7cc:f5f9 with SMTP id g11-20020a056402090b00b00412a7ccf5f9mr21154760edz.136.1646083539437; Mon, 28 Feb 2022 13:25:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646083539; cv=none; d=google.com; s=arc-20160816; b=DG5gnZ+z+fLfAAZWSF/omXT7A2MypTY2B6KBxKFL0ZCeddNBmUGJApJotuVwCuQ3/P h/MZWQahOQ9rjatEriO9BQAex3vDVIjocfimoJzOLlxE78h4Dxx2hHRaxhOIZRd5RLGS /3bw+6BBLvR5MBbewqz9BzOS3V4ENhMinbLQ3iSxlCgkMYkidFD87Sw/yiNBYAdGczPI WDp1Z0XSfHlnzcZYTcRSqlBYTW0skZ8UZc4NvalyMrICFVZJTOF+35hOd3imZVkVfqWg SmB9pvrip3T2isFIpwYhon6QNiPUJ+tFGwUQkw/r+2pk+Ly40o2n46IuSnz8P2vsmvKQ F10g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=QC3nIz+n91wpfCsPUnRTYwS86Hu+HklVlqnCRUpphJc=; b=ZdlwtN25vaia5/Bdxw5INN8E9dNaZWZQ8jGEfQATd512AH/oxpJQVaRaXVFhaH+UKS 7HeAPobuo5cdXGm96UPStDWp5MLLoSEjuq9XtZbAeHnH3J7PB5+yiYSkTGbLxmP5RDGE tlttH30WcioTjnTQ5aHp7T9sY+ux0KtwhMOc7Of7jKxobZSEz2CKeILtigCP0fXyMGCh e4vXRN5++X8dlr8TmOM3R2HMc4KRm6hB8kYQtr2rqxgh3GHv+TRDk4C70DM651IHeYZB lu/Fo3GqKZAZx3QRb5XTr9KSnAkC4E0NnJOLZk3W4HAAgv1z5wdMN+JYpa4+RxDxkRXx E7Zg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o20-20020a170906775400b006cfea3fc8e2si6669692ejn.415.2022.02.28.13.25.14; Mon, 28 Feb 2022 13:25:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230089AbiB1VNy (ORCPT + 99 others); Mon, 28 Feb 2022 16:13:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbiB1VNu (ORCPT ); Mon, 28 Feb 2022 16:13:50 -0500 Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0A2D5ECB1A; Mon, 28 Feb 2022 13:12:56 -0800 (PST) Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 21SKr95E005627; Mon, 28 Feb 2022 14:53:09 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 21SKr7Xe005624; Mon, 28 Feb 2022 14:53:07 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Mon, 28 Feb 2022 14:53:07 -0600 From: Segher Boessenkool To: Linus Torvalds Cc: Christian =?iso-8859-1?Q?K=F6nig?= , linux-wireless , alsa-devel@alsa-project.org, KVM list , "Gustavo A. R. Silva" , linux-iio@vger.kernel.org, nouveau@lists.freedesktop.org, Rasmus Villemoes , dri-devel , Cristiano Giuffrida , "Bos, H.J." , linux1394-devel@lists.sourceforge.net, drbd-dev@lists.linbit.com, linux-arch , CIFS , linux-aspeed@lists.ozlabs.org, linux-scsi , linux-rdma , linux-staging@lists.linux.dev, amd-gfx list , Jason Gunthorpe , intel-wired-lan@lists.osuosl.org, kgdb-bugreport@lists.sourceforge.net, bcm-kernel-feedback-list@broadcom.com, Dan Carpenter , Linux Media Mailing List , Kees Cook , Arnd Bergman , Linux PM , intel-gfx , Brian Johannesmeyer , Nathan Chancellor , dma , Christophe JAILLET , Jakob Koschel , v9fs-developer@lists.sourceforge.net, linux-tegra , Thomas Gleixner , Andy Shevchenko , Linux ARM , linux-sgx@vger.kernel.org, linux-block , Netdev , linux-usb@vger.kernel.org, samba-technical@lists.samba.org, Linux Kernel Mailing List , Linux F2FS Dev Mailing List , tipc-discussion@lists.sourceforge.net, Linux Crypto Mailing List , linux-fsdevel , linux-mediatek@lists.infradead.org, Andrew Morton , linuxppc-dev , Mike Rapoport Subject: Re: [PATCH 2/6] treewide: remove using list iterator after loop body as a ptr Message-ID: <20220228205307.GD614@gate.crashing.org> References: <20220228110822.491923-1-jakobkoschel@gmail.com> <20220228110822.491923-3-jakobkoschel@gmail.com> <2e4e95d6-f6c9-a188-e1cd-b1eae465562a@amd.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 28, 2022 at 12:14:44PM -0800, Linus Torvalds wrote: > On Mon, Feb 28, 2022 at 12:10 PM Linus Torvalds > wrote: > > > > We can do > > > > typeof(pos) pos > > > > in the 'for ()' loop, and never use __iter at all. > > > > That means that inside the for-loop, we use a _different_ 'pos' than outside. > > The thing that makes me throw up in my mouth a bit is that in that > > typeof(pos) pos > > the first 'pos' (that we use for just the typeof) is that outer-level > 'pos', IOW it's a *different* 'pos' than the second 'pos' in that same > declaration that declares the inner level shadowing new 'pos' > variable. The new "pos" has not yet been declared, so this has to refer to the outer "pos", it cannot be the inner one. Because it hasn't been declared yet :-) Compare this to typeof (pos) pos = pos; where that last "pos" *does* refer to the newly declared one: that declaration has already been done! (So this code is UB btw, 6.3.2.1/2). > If I was a compiler person, I would say "Linus, that thing is too ugly > to live", and I would hate it. I'm just hoping that even compiler > people say "that's *so* ugly it's almost beautiful". It is perfectly well-defined. Well, it would be good if we (GCC) would document it does work, and if someone tested it on LLVM as well. But it is really hard to implement it to *not* work :-) > Because it does seem to work. It's not pretty, but hey, it's not like > our headers are really ever be winning any beauty contests... It is very pretty! Needs a comment though :-) Segher