[英]Is the GCC option -Wdeclaration-after-statement purely stylistic?
[英]PostgreSQL C Extensions without -Wdeclaration-after-statement
目前,當我編譯我的擴展時,我得到,
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
57 | uint32 n = fctx->n;
PostgreSQL 當前在編譯期間使用-Wdeclaration-after-statement
。 他們在我的機器上的pgxs
全局 make 文件中專門設置了這個選項,
/usr/lib/postgresql/13/lib/pgxs/src/Makefile.global
它是用他們的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
無論如何要禁用-Wdeclaration-after-statement
還是每個 PostgreSQL 擴展作者都必須采用相同的約定? 我可以在我的擴展中覆蓋 CFLAGS 嗎?
可能您可以通過鏈接中描述的說明覆蓋它
變量PG_CFLAGS
將被附加到CFLAGS
,所以只需添加-Wno-declaration-after-statement
我能夠通過結束我的擴展的Makefile
來消除這些警告,
$(OBJS): CFLAGS += $(PERMIT_DECLARATION_AFTER_STATEMENT)
感謝 RhodiumToad 在ircs://irc.libera.chat:6697/#postgresql
,他繼續說
配置測試
-Wno-declaration-after-statement
有效並相應地設置該變量實際上我認為它會檢查-Wdeclaration-after-statement
,如果有效,則假設 -Wno-... 也有效,您可以放置該規則在包含$(PGXS)
,如果需要或以定義PERMIT_DECLARATION_AFTER_STATEMENT
為條件,您可以使其以$(MAJORVERSION)
為條件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.