Re: Windows build warnings

Daniel Gustafsson <daniel@yesql.se>

From: Daniel Gustafsson <daniel@yesql.se>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>, Greg Nancarrow <gregn4422@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2021-11-22T15:22:20Z
Lists: pgsql-hackers
> On 22 Nov 2021, at 16:06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> 
> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
>> .. but see
>> https://postgr.es/m/CAH2-WznwWU+9on9nZCnZtk7uA238MCTgPxYr1Ty7U_Msn5ZGwQ@mail.gmail.com
>> where this was already discussed.  I think if we're going to workaround
>> PG_USED_FOR_ASSERTS_ONLY not actually working, we may as well get rid of
>> it entirely.  My preference would be to fix it so that it works on more
>> platforms (at least Windows in addition to GCC).
> 
> Yeah, I do not think there is a reason to change the code if it's using
> PG_USED_FOR_ASSERTS_ONLY properly.  We should either make that macro
> work on $compiler, or ignore such warnings from $compiler.

Fair enough.  Looking at where we use PG_USED_FOR_ASSERTS_ONLY (and where it
works), these two warnings are the only places where we apply it to a pointer
typedef (apart from one place where the variable is indeed used outside of
asserts).  Since it clearly works in all other cases, I wonder if something
like the below sketch could make MSVC handle the attribute?

diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c
index 5c0b60319d..9701c9eba0 100644
--- a/src/backend/access/heap/pruneheap.c
+++ b/src/backend/access/heap/pruneheap.c
@@ -855,7 +855,7 @@ heap_page_prune_execute(Buffer buffer,
 {
        Page            page = (Page) BufferGetPage(buffer);
        OffsetNumber *offnum;
-       HeapTupleHeader htup PG_USED_FOR_ASSERTS_ONLY;
+       HeapTupleHeaderData *htup PG_USED_FOR_ASSERTS_ONLY;

        /* Shouldn't be called unless there's something to do */
        Assert(nredirected > 0 || ndead > 0 || nunused > 0);
@@ -867,7 +867,7 @@ heap_page_prune_execute(Buffer buffer,
                OffsetNumber fromoff = *offnum++;
                OffsetNumber tooff = *offnum++;
                ItemId          fromlp = PageGetItemId(page, fromoff);
-               ItemId          tolp PG_USED_FOR_ASSERTS_ONLY;
+               ItemIdData              *tolp PG_USED_FOR_ASSERTS_ONLY;

 #ifdef USE_ASSERT_CHECKING

--
Daniel Gustafsson		https://vmware.com/




Commits

  1. Disable unused-variable warning C4101 in MSVC

  2. Remove PF_USED_FOR_ASSERTS_ONLY from variables in general use

  3. Fix handling of non-key columns get_index_column_opclass()