Home > Net >  PostgreSQL C Extensions without -Wdeclaration-after-statement
PostgreSQL C Extensions without -Wdeclaration-after-statement

Time:10-31

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?

CodePudding user response:

Probably you can override it by the instructions described in the link

The variable PG_CFLAGS will be appended to CFLAGS, so just add -Wno-declaration-after-statement

CodePudding user response:

I was able to squelch these warnings by ending my extension's Makefile with,

$(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 on PERMIT_DECLARATION_AFTER_STATEMENT being defined

  • Related