Subject: Warning in geqo_main.c from clang 13

From: Thomas Munro <[email-masked]>
Date: Wed, 24 Nov 2021 15:31:49 +1300

Hi,

Clang 13 on my machine and peripatus (but not Apple clang 13 on eg
sifika, I'm still confused about Apple's versioning but I think that's
really llvm 12-based) warns:

geqo_main.c:86:8: warning: variable 'edge_failures' set but not used
[-Wunused-but-set-variable]
        int                     edge_failures = 0;

Here's one way to silence it.
diff --git a/src/backend/optimizer/geqo/geqo_main.c b/src/backend/optimizer/geqo/geqo_main.c
index 09d9e7d4dd..b18eccfae4 100644
--- a/src/backend/optimizer/geqo/geqo_main.c
+++ b/src/backend/optimizer/geqo/geqo_main.c
@@ -83,8 +83,10 @@ geqo(PlannerInfo *root, int number_of_rels, List *initial_rels)
 
 #if defined(ERX)
 	Edge	   *edge_table;		/* list of edges */
+#if defined(GEQO_DEBUG)
 	int			edge_failures = 0;
 #endif
+#endif
 #if defined(CX) || defined(PX) || defined(OX1) || defined(OX2)
 	City	   *city_table;		/* list of cities */
 #endif
@@ -187,7 +189,10 @@ geqo(PlannerInfo *root, int number_of_rels, List *initial_rels)
 		kid = momma;
 
 		/* are there any edge failures ? */
-		edge_failures += gimme_tour(root, edge_table, kid->string, pool->string_length);
+#if defined(GEQO_DEBUG)
+		edge_failures +=
+#endif
+			gimme_tour(root, edge_table, kid->string, pool->string_length);
 #elif defined(PMX)
 		/* PARTIALLY MATCHED CROSSOVER */
 		pmx(root, momma->string, daddy->string, kid->string, pool->string_length);

---

From: Tom Lane <[email-masked]>
Date: Tue, 23 Nov 2021 22:17:54 -0500

> [-Wunused-but-set-variable]

Yeah, I noticed that a week or two ago, but didn't see a simple fix.

> Here's one way to silence it.

I'm kind of inclined to just drop the edge_failures recording/logging
altogether, rather than make that rats-nest of #ifdefs even worse.
It's not like anyone has cared about that number in the last decade
or two.

			regards, tom lane