headerscheck warnings with late-model gcc - Mailing list pgsql-hackers

From Tom Lane
Subject headerscheck warnings with late-model gcc
Date
Msg-id 1127775.1754417387@sss.pgh.pa.us
Whole thread Raw
Responses Re: headerscheck warnings with late-model gcc
List pgsql-hackers
Using gcc 15.1.1 (from Fedora 42) I see these warnings that
didn't appear with older gcc:

$ src/tools/pginclude/headerscheck
In file included from /tmp/headerscheck.xp0AI5/test.c:2:
./src/common/kwlist_d.h:1163:23: warning: no previous declaration for 'ScanKeywords' [-Wmissing-variable-declarations]
 1163 | const ScanKeywordList ScanKeywords = {
      |                       ^~~~~~~~~~~~
In file included from /tmp/headerscheck.xp0AI5/test.c:2:
./src/interfaces/ecpg/test/preproc/strings.h:1:13: warning: no previous declaration for 's1'
[-Wmissing-variable-declarations]
    1 | char       *s1,
      |             ^~
./src/interfaces/ecpg/test/preproc/strings.h:2:21: warning: no previous declaration for 's2'
[-Wmissing-variable-declarations]
    2 |                    *s2,
      |                     ^~
./src/interfaces/ecpg/test/preproc/strings.h:3:21: warning: no previous declaration for 's3'
[-Wmissing-variable-declarations]
    3 |                    *s3,
      |                     ^~
./src/interfaces/ecpg/test/preproc/strings.h:4:21: warning: no previous declaration for 's4'
[-Wmissing-variable-declarations]
    4 |                    *s4,
      |                     ^~
./src/interfaces/ecpg/test/preproc/strings.h:5:21: warning: no previous declaration for 's5'
[-Wmissing-variable-declarations]
    5 |                    *s5,
      |                     ^~
./src/interfaces/ecpg/test/preproc/strings.h:6:21: warning: no previous declaration for 's6'
[-Wmissing-variable-declarations]
    6 |                    *s6,
      |                     ^~
./src/interfaces/ecpg/test/preproc/strings.h:7:21: warning: no previous declaration for 's7'
[-Wmissing-variable-declarations]
    7 |                    *s7,
      |                     ^~
./src/interfaces/ecpg/test/preproc/strings.h:8:21: warning: no previous declaration for 's8'
[-Wmissing-variable-declarations]
    8 |                    *s8;
      |                     ^~

While we could possibly get away with making headerscheck ignore that
ecpg test header, it seems unwise to skip kwlist_d.h.  So I propose
the attached patch, which I've confirmed silences these warnings.

Curiously, no such complaints appear with cpluspluscheck (which is
using g++ 15.1.1).  I don't really understand why not: why would
they have turned on -Wmissing-variable-declarations by default
for C but not C++?  But anyway, since there doesn't seem to be
any C++ compatibility issue here, I think it's sufficient to fix
this in master and not back-patch.

            regards, tom lane

diff --git a/src/interfaces/ecpg/test/expected/preproc-strings.c b/src/interfaces/ecpg/test/expected/preproc-strings.c
index a26817968de..55859b624eb 100644
--- a/src/interfaces/ecpg/test/expected/preproc-strings.c
+++ b/src/interfaces/ecpg/test/expected/preproc-strings.c
@@ -18,6 +18,16 @@
 #line 3 "strings.pgc"
 /* exec sql begin declare section */
 #line 1 "strings.h"
+/* This extern silences headerscheck warnings with some gcc versions */
+
+
+
+
+
+
+
+
+



@@ -29,7 +39,10 @@

 #line 5 "strings.pgc"

-#line 1 "strings.h"
+#line 2 "strings.h"
+ extern char * s1 , * s2 , * s3 , * s4 , * s5 , * s6 , * s7 , * s8 ;
+
+#line 11 "strings.h"
  char * s1 , * s2 , * s3 , * s4 , * s5 , * s6 , * s7 , * s8 ;
 /* exec sql end declare section */
 #line 5 "strings.pgc"
diff --git a/src/interfaces/ecpg/test/preproc/strings.h b/src/interfaces/ecpg/test/preproc/strings.h
index edb5be5339e..71581d6f94a 100644
--- a/src/interfaces/ecpg/test/preproc/strings.h
+++ b/src/interfaces/ecpg/test/preproc/strings.h
@@ -1,3 +1,13 @@
+/* This extern silences headerscheck warnings with some gcc versions */
+extern char *s1,
+           *s2,
+           *s3,
+           *s4,
+           *s5,
+           *s6,
+           *s7,
+           *s8;
+
 char       *s1,
            *s2,
            *s3,
diff --git a/src/tools/gen_keywordlist.pl b/src/tools/gen_keywordlist.pl
index 6ec83ff33f9..8825b4476ac 100644
--- a/src/tools/gen_keywordlist.pl
+++ b/src/tools/gen_keywordlist.pl
@@ -169,7 +169,16 @@ printf $kwdef qq|static %s\n|, $f;

 # Emit the struct that wraps all this lookup info into one variable.

-printf $kwdef "static " if !$extern;
+if ($extern)
+{
+    # This redundant extern declaration is needed to silence headerscheck
+    # warnings with some gcc versions.
+    printf $kwdef "extern const ScanKeywordList %s;\n\n", $varname;
+}
+else
+{
+    printf $kwdef "static ";
+}
 printf $kwdef "const ScanKeywordList %s = {\n", $varname;
 printf $kwdef qq|\t%s_kw_string,\n|, $varname;
 printf $kwdef qq|\t%s_kw_offsets,\n|, $varname;

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Datum as struct
Next
From: Tom Lane
Date:
Subject: Re: Bug in brin_minmax_multi_distance_numeric()