Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vOuVV-00CLCu-1P for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Nov 2025 09:11:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vOuVU-00AEMZ-0H for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Nov 2025 09:11:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vOuVT-00AEMP-2G for pgsql-hackers@lists.postgresql.org; Fri, 28 Nov 2025 09:11:12 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vOuVP-001vte-0m for pgsql-hackers@lists.postgresql.org; Fri, 28 Nov 2025 09:11:11 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4dHnbD693XzyQH; Fri, 28 Nov 2025 11:11:04 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1764321065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wMvPBANrMYpJ4mfukWY0FtfT+3sim1UY3sb0lMXqypc=; b=ejbt1+lMZ1qYaFE6V5n38im/PHp3DwubJgrDs94sdRzQvVef962TmRWqyncaqpPpeddBhO 99b92OMRKE0RwSD/uRh1lE6mEsNMARFRjgKgc/uRbh2YmeO9xW/ZWbEw+yuBhW+wEVv4xr zZ8sdGl0y3lsDmNGiZ8Da5vROflZogM= ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=meesny; cv=none; t=1764321065; b=U12I+lnSrRd7BhIx4EvHNXVEVfhW49DiIeWpA6ANxA549u81hQ9/DqkRkX3qCmZM6/kGml HPbBPa4/1XVefa/q6LknPpbReRI9M6TWU0CslO4kmOqTh/Dn2jz1wlVYxeVvcLUOHHsXVW Jf2dG/hNhrtI0+cv3yZB2WcneoVB00Y= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1764321065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wMvPBANrMYpJ4mfukWY0FtfT+3sim1UY3sb0lMXqypc=; b=k00n1DzONLWETry3s0jaUJXURYG9ZEgDojzTIBuW+X1G65y3Ob311T0NENW7qTBOra46fj 1oM0YJJ3HeO7ReWvb0PpGrpcHN7I8FfP6e7qkVFdtOF6pJnJwrodHHXFw4idDmSXvxvKJR UwqCLbzpzsO2v11Yj8/OS0wBzud7dpw= Message-ID: <70eaa01a-2699-43c3-b175-ada78aed5448@iki.fi> Date: Fri, 28 Nov 2025 11:11:04 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Cleanup shadows variable warnings, round 1 To: Chao Li , Postgres hackers References: Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 28/11/2025 10:16, Chao Li wrote: > Hi Hackers, > > While reviewing [1], it makes me recall an experience where I had a > patch ready locally, but CommitFest CI failed with a shadows-variable > warning. Now I understand that -Wall doesn't by default enable -Wshadows > with some compilers like clang. > > I did a clean build with manually enabling -Wshadow and > surprisingly found there are a lot of such warnings in the current code > base, roughly ~200 occurrences. > > As there are too many, I plan to fix them all in 3-4 rounds. For round 1 > patch, I'd see any objection, then decide if to proceed more rounds. I don't know if we've agreed on a goal of getting rid of all shadowing, it's a lot of code churn. I agree shadowing is often confusing and error-prone, so maybe it's worth it. On the patch itself: In some of the cases, I think we should rename the global / outer-scoped variable instead of the local variable. For example, it's pretty insane that we apparently have a global variable called 'days'. :-) Let's think a little harder about the new names. For example: > @@ -1274,8 +1274,8 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control, > Datum old = t_sql; > char *reqextname = (char *) lfirst(lc); > Oid reqschema = lfirst_oid(lc2); > - char *schemaName = get_namespace_name(reqschema); > - const char *qSchemaName = quote_identifier(schemaName); > + char *schemaname = get_namespace_name(reqschema); > + const char *qSchemaName = quote_identifier(schemaname); > char *repltoken; > > repltoken = psprintf("@extschema:%s@", reqextname); Having two local variables that only differ in case is also confusing. We're using the 'req*' prefix here for the other variables, so I think e.g. 'reqSchemaName' would be a good name here. (I didn't go through the whole patch, these were just a few things that caught my eye at quick glance) - Heikki