consider -Wmissing-variable-declarations

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: consider -Wmissing-variable-declarations
Date: 2024-05-09 09:23:32
Message-ID: e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Attachment Content-Type Size
v1-0001-Add-Wmissing-variable-declarations-to-the-standar.patch text/plain 9.5 KB
v1-0002-Convert-some-extern-variables-to-static.patch text/plain 29.4 KB
v1-0003-Add-missing-includes.patch text/plain 2.3 KB
v1-0004-Fix-Wmissing-variable-declarations-warnings-for-f.patch text/plain 974 bytes
v1-0005-Fix-Wmissing-variable-declarations-warnings-in-bi.patch text/plain 4.2 KB
v1-0006-XXX-Fix-Wmissing-variable-declarations-warnings-f.patch text/plain 6.4 KB
v1-0007-XXX-other-stuff.patch text/plain 1.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andy Fan 2024-05-09 09:44:49 Re: Parallel CREATE INDEX for GIN indexes
Previous Message Aleksander Alekseev 2024-05-09 09:18:44 Re: First draft of PG 17 release notes