consider -Wmissing-variable-declarations

Peter Eisentraut <peter@eisentraut.org>

From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2024-05-09T09:23:32Z
Lists: pgsql-hackers

Attachments

In [0] I had noticed that we have no automated verification that global 
variables are declared in header files.  (For global functions, we have 
this through -Wmissing-prototypes.)  As I mentioned there, I discovered 
the Clang compiler option -Wmissing-variable-declarations, which does 
exactly that.  Clang has supported this for quite some time, and GCC 14, 
which was released a few days ago, now also supports it.  I went and 
installed this option into the standard build flags and cleaned up the 
warnings it found, which revealed a number of interesting things.

I think these checks are important.  We have been trying to mark global 
variables as PGDLLIMPORT consistently, but that only catches variables 
declared in header files.  Also, a threading project would surely 
benefit from global variables (thread-local variables?) having 
consistent declarations.

Attached are patches organized by sub-topic.  The most dubious stuff is 
in patches 0006 and 0007.  A bunch of GUC-related variables are not in 
header files but are pulled in via ad-hoc extern declarations.  I can't 
recognize an intentional scheme there, probably just done for 
convenience or copied from previous practice.  These should be organized 
into appropriate header files.


[0]: 
https://www.postgresql.org/message-id/c4ac402f-9d7b-45fa-bbc1-4a5bf0a9f206@eisentraut.org

Commits

  1. Use CXXFLAGS instead of CFLAGS for linking C++ code

  2. Add -Wmissing-variable-declarations to the standard compilation flags

  3. Include bison header files into implementation files

  4. Fix -Wmissing-variable-declarations warnings for float.c special case

  5. Add extern declarations for Bison global variables

  6. Move all extern declarations for GUC variables to header files

  7. Move extern declarations for EXEC_BACKEND to header files

  8. Get rid of a global variable

  9. Add missing includes for some global variables

  10. Convert some extern variables to static

  11. Improve some global variable declarations

  12. Remove useless extern keywords