Currently, when I compile my extension I get,
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
57 | uint32 n = fctx->n;
PostgreSQL currently uses -Wdeclaration-after-statement
during compilation. They set this option specifically in their pgxs
global make file on my machine that's at,
/usr/lib/postgresql/13/lib/pgxs/src/Makefile.global
It is set with their CFLAGS
,
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer
Is there anyway to disable -Wdeclaration-after-statement
or does every PostgreSQL extension author have to adopt this same convention? Can I override CFLAGS in my extension?
I was able to squelch these warnings by ending my extension's Makefile
like,
PG_CFLAGS += $(PERMIT_DECLARATION_AFTER_STATEMENT)
include $(PGXS)
RhodiumToad provided an alternative way after include $(PGXS)
include $(PGXS)
$(OBJS): CFLAGS += $(PERMIT_DECLARATION_AFTER_STATEMENT)
Thanks goes out RhodiumToad on ircs://irc.libera.chat:6697/#postgresql
, he goes on to say
configure tests whether
-Wno-declaration-after-statement
works and sets up that variable accordingly well actually I think it checks for-Wdeclaration-after-statement
and if that works, assumes -Wno-... works too you can put that rule after including$(PGXS)
, so you can make it conditional on$(MAJORVERSION)
if need be or conditional onPERMIT_DECLARATION_AFTER_STATEMENT
being defined