Compiler warning when using TRGM_REGEXP_DEBUG

Поиск
Список
Период
Сортировка
Искать

Compiler warning when using TRGM_REGEXP_DEBUG

От:
Sergei Kornilov <sk@zsrv.org>
Дата:
Hello!

I was looking into how pg_trgm index support works with regular expressions. When building HEAD with the TRGM_REGEXP_DEBUG option, my compiler warns:

./configure CFLAGS="-DTRGM_REGEXP_DEBUG"
cd contrib/pg_trgm/
make -s

trgm_regexp.c: In function ‘printSourceNFA’:
trgm_regexp.c:2142:41: warning: declaration of ‘i’ shadows a previous local [-Wshadow=compatible-local]
 2142 |                 int                     i,
      |                                         ^
trgm_regexp.c:2133:33: note: shadowed declaration is here
 2133 |         int                     i;

I am using gcc (Debian 12.2.0-14+deb12u1) 12.2.0.

Does it make sense to fix this warning? It is possible to either rename this variable or remove the second declaration (the variable is used in another loop after this code).

--- a/contrib/pg_trgm/trgm_regexp.c
+++ b/contrib/pg_trgm/trgm_regexp.c
@@ -2139,8 +2139,7 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors)
     for (state = 0; state < nstates; state++)
     {
         regex_arc_t *arcs;
-        int         i,
-                    arcsCount;
+        int         arcsCount;
 
         appendStringInfo(&buf, "s%d", state);
         if (pg_reg_getfinalstate(regex) == state)

regards, Sergei


Re: Compiler warning when using TRGM_REGEXP_DEBUG

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Sergei Kornilov  writes:
> I was looking into how pg_trgm index support works with regular expressions. When building HEAD with the TRGM_REGEXP_DEBUG option, my compiler warns:

> trgm_regexp.c: In function ‘printSourceNFA’:
> trgm_regexp.c:2142:41: warning: declaration of ‘i’ shadows a previous local [-Wshadow=compatible-local]
>  2142 |                 int                     i,
>       |                                         ^
> trgm_regexp.c:2133:33: note: shadowed declaration is here
>  2133 |         int                     i;

Ah, yeah, I see it too with -DTRGM_REGEXP_DEBUG.

> Does it make sense to fix this warning? It is possible to either rename this variable or remove the second declaration (the variable is used in another loop after this code).

I think if we need to touch it, we should modernize all the loops in
this function to use loop-local variables.  Will see to it.

			regards, tom lane


FAQ