[{"id":13206,"web_url":"https://patchwork.libcamera.org/comment/13206/","msgid":"<20201014124243.4hek53zkt7wgzfbp@oden.dyn.berto.se>","date":"2020-10-14T12:42:43","subject":"Re: [libcamera-devel] [PATCH 10/10] meson: Enable shadowed variable\n\twarning","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Kieran,\n\nOn 2020-10-13 16:12:41 +0100, Kieran Bingham wrote:\n> Shadowing variables can lead to unexpected bugs where a code path\n> utilises a variable that may not have been intended by the developer,\n> leading to hard to find bugs.\n> \n> Enable warnings for shadowed variables as defined at:\n>   https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wshadow\n> \n> As an effect of utilising -Werror, this will cause variable or type\n> shadowing to become a build-time error.\n> \n> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nI like it!\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> \n> ---\n> \n> The reference here is that I lost around 2 hours digging into a bug that\n> looked like some other code path was calling a destructor or such, but\n> was because I had accidentally aliased a private member variable in the\n> constructor, so all my initialisation was lost after the constructor\n> completed.\n> \n>  meson.build | 1 +\n>  1 file changed, 1 insertion(+)\n> \n> diff --git a/meson.build b/meson.build\n> index de15cc16da81..10423f523ca5 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -38,6 +38,7 @@ if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOUR\n>  endif\n>  \n>  common_arguments = [\n> +    '-Wshadow',\n>      '-include', 'config.h',\n>  ]\n>  \n> -- \n> 2.25.1\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 26690BEEE0\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Oct 2020 12:42:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E5E3660E97;\n\tWed, 14 Oct 2020 14:42:46 +0200 (CEST)","from mail-lf1-x141.google.com (mail-lf1-x141.google.com\n\t[IPv6:2a00:1450:4864:20::141])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6A32560E79\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Oct 2020 14:42:45 +0200 (CEST)","by mail-lf1-x141.google.com with SMTP id z2so3556965lfr.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Oct 2020 05:42:45 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\tc17sm1104015lfi.35.2020.10.14.05.42.43\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 14 Oct 2020 05:42:44 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com\n\theader.b=\"olTDtka/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=Y1oKodrFb/R/3zaYQS9OpDUHBJprahhYewirCree9Sw=;\n\tb=olTDtka/vQ0n7MmzqpAg3Kt90z+d/LMoh4PPE/pXHFqct4b/XB0qX8mFGF5SVjXSrp\n\tifUCuyLOXdoPavbez9SHtoYlU4B4LVq8vYPguLTtHdxKu5g9mpZezPPcpO6aQt3HGsXU\n\tMiYapn/4c1/4nB8ikiHGUlDXYuca2VWACEM6ozuaIBIqoRnghqSZeHUBE81AVL+nwZ5x\n\txU0/hPK3aY80Ey/KzGufydE9u9OnUHz+aG7PKJpnCybcWqYRuSOZUEYTFlK7hvO62/rQ\n\tBVmtg85UbbxtBKuc5GvKvl+G+EQbeAKsAKj+BptEW33Km1un2zcYN15xmffRGeolTwY3\n\trlLQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=Y1oKodrFb/R/3zaYQS9OpDUHBJprahhYewirCree9Sw=;\n\tb=RYr2jFSDrQLnKdnxMnlGyBVqQ03BsVSO25UhuexK/T3Z2c5yjPE47ZnE2N3q7CNXf7\n\tdEgsqlDWddLR1MFOyZgsEkuNejCO2OIGuPpxdvyEs1Fu2EGaMG9IBPNicuVllk1+18YG\n\t6TmVFJX2h3khF4bv8MZWwYEUPV1od0c7luR2oHAFZ30l//MAFoY5xNpoFS5A96zNsHYd\n\t3t8MyK+/o+DpfM8bKYhFIFX7Aqymq5TGkj9r0EiGdcCKe4yY9gtxAUJ69KeooekFvQpz\n\twxhN0UF10WoOexbQebSGN8IQi4V1PXor/CqEYRTfnOEsjBfNVf/T+811jN1BR0FN0udk\n\tyMVA==","X-Gm-Message-State":"AOAM531pVkErY+l7wz8kNpCJCU6CEP88nrI6Yw0QpHZ8NkhbRf7FNmHt\n\t63zvr6bTNgAHHtM/N6PaPz1POI+ov7IVXQ==","X-Google-Smtp-Source":"ABdhPJxdOl/rPDFKD2FNuQ4mztZeSd64R3HO/Wb+/n9vSGb/qT1PF8Xz1dJvsmpXV7rcfv4jXS+ssA==","X-Received":"by 2002:ac2:5094:: with SMTP id\n\tf20mr1318716lfm.123.1602679364887; \n\tWed, 14 Oct 2020 05:42:44 -0700 (PDT)","Date":"Wed, 14 Oct 2020 14:42:43 +0200","From":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<20201014124243.4hek53zkt7wgzfbp@oden.dyn.berto.se>","References":"<20201013151241.3557005-1-kieran.bingham@ideasonboard.com>\n\t<20201013151241.3557005-11-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201013151241.3557005-11-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 10/10] meson: Enable shadowed variable\n\twarning","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"iso-8859-1\"","Content-Transfer-Encoding":"quoted-printable","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":13215,"web_url":"https://patchwork.libcamera.org/comment/13215/","msgid":"<20201015134601.GF3957@pendragon.ideasonboard.com>","date":"2020-10-15T13:46:01","subject":"Re: [libcamera-devel] [PATCH 10/10] meson: Enable shadowed variable\n\twarning","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Tue, Oct 13, 2020 at 04:12:41PM +0100, Kieran Bingham wrote:\n> Shadowing variables can lead to unexpected bugs where a code path\n> utilises a variable that may not have been intended by the developer,\n> leading to hard to find bugs.\n> \n> Enable warnings for shadowed variables as defined at:\n>   https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wshadow\n> \n> As an effect of utilising -Werror, this will cause variable or type\n> shadowing to become a build-time error.\n> \n> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> \n> The reference here is that I lost around 2 hours digging into a bug that\n> looked like some other code path was calling a destructor or such, but\n> was because I had accidentally aliased a private member variable in the\n> constructor, so all my initialisation was lost after the constructor\n> completed.\n\nIt's sometimes nice to be able to shadow variables, but I think the\ndebugging pain is too high of a cost for that.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  meson.build | 1 +\n>  1 file changed, 1 insertion(+)\n> \n> diff --git a/meson.build b/meson.build\n> index de15cc16da81..10423f523ca5 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -38,6 +38,7 @@ if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOUR\n>  endif\n>  \n>  common_arguments = [\n> +    '-Wshadow',\n>      '-include', 'config.h',\n>  ]","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 02D5ABE905\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 15 Oct 2020 13:46:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6C9F160E8D;\n\tThu, 15 Oct 2020 15:46:51 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 87D24605BF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 15 Oct 2020 15:46:49 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9B0F8556;\n\tThu, 15 Oct 2020 15:46:48 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"jys0F3TR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1602769609;\n\tbh=H2ue5Y9CM1oTf5FBmfLS/7iiNY42+VSVAtkhf64TRtc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=jys0F3TRJhWtqn0G4yLCveAnvCYMao0qoLIDKfiEmflTFBh0Yu5iBKiIus1O4isBP\n\tWWkWSVVnohazwZwz2aNzKNR39pZaDxpKPy5Ks1z2xnueQUDZwboQnRmoxgxjhyQ2K6\n\tlSeTyiOs9OC4xV6APDdtpK9kzXVJQqxef+BxVyKQ=","Date":"Thu, 15 Oct 2020 16:46:01 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<20201015134601.GF3957@pendragon.ideasonboard.com>","References":"<20201013151241.3557005-1-kieran.bingham@ideasonboard.com>\n\t<20201013151241.3557005-11-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201013151241.3557005-11-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 10/10] meson: Enable shadowed variable\n\twarning","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]