On Tue, Oct 11, 2022 at 01:16:50PM +1300, David Rowley wrote:
> Aside from this issue, if anything I'd be keen to go a little further
> with this and upgrade to -Wshadow=local. The reason being is that I
> noticed that the const qualifier is not classed as "compatible" with
> the equivalently named and typed variable without the const qualifier.
> ISTM that there's close to as much opportunity to mix up two variables
> with the same name that are const and non-const as there are two
> variables with the same const qualifier. However, I'll be waiting for
> the dust to settle on the current flags before thinking any more about
> that.

-Wshadow=compatible-local causes one extra warning in postgres.c with
-DWRITE_READ_PARSE_PLAN_TREES:
postgres.c: In function ‘pg_rewrite_query’:
postgres.c:818:37: warning: declaration of ‘query’ shadows a parameter 
[-Wshadow=compatible-local]
  818 |                         Query      *query = lfirst_node(Query, lc);
      |                                     ^~~~~
postgres.c:771:25: note: shadowed declaration is here
  771 | pg_rewrite_query(Query *query)
      |                  ~~~~~~~^~~~~

Something like the patch attached would deal with this one.
--
Michael
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 5352d5f4c6..27dee29f42 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -815,15 +815,15 @@ pg_rewrite_query(Query *query)
 
 		foreach(lc, querytree_list)
 		{
-			Query	   *query = lfirst_node(Query, lc);
-			char	   *str = nodeToString(query);
+			Query	   *curr_query = lfirst_node(Query, lc);
+			char	   *str = nodeToString(curr_query);
 			Query	   *new_query = stringToNodeWithLocations(str);
 
 			/*
 			 * queryId is not saved in stored rules, but we must preserve it
 			 * here to avoid breaking pg_stat_statements.
 			 */
-			new_query->queryId = query->queryId;
+			new_query->queryId = curr_query->queryId;
 
 			new_list = lappend(new_list, new_query);
 			pfree(str);

Attachment: signature.asc
Description: PGP signature

Reply via email to