| From: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
|---|---|
| To: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Cleanup shadows variable warnings, round 1 |
| Date: | 2025-11-28 09:11:04 |
| Message-ID: | 70eaa01a-2699-43c3-b175-ada78aed5448@iki.fi |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Banck | 2025-11-28 09:15:52 | Re: How can end users know the cause of LR slot sync delays? |
| Previous Message | Bertrand Drouvot | 2025-11-28 09:06:45 | Re: Remove useless casting to the same type |