Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6618891

Browse files
committed
Add -Wmissing-variable-declarations to the standard compilation flags
This warning flag detects global variables not declared in headerfiles. This is similar to what -Wmissing-prototypes does forfunctions. (More correctly, it is similar to what-Wmissing-declarations does for functions, but -Wmissing-prototypes isa superset of that in C.)This flag is new in GCC 14. Clang has supported it for a while.Several recent commits have cleaned up warnings triggered by this, soit should now be clean.Reviewed-by: Andres Freund <andres@anarazel.de>Discussion:https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org
1 parent7926a9a commit6618891

File tree

9 files changed

+76
-1
lines changed

9 files changed

+76
-1
lines changed

‎configure

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ CXXFLAGS_SL_MODULE
741741
CFLAGS_SL_MODULE
742742
CFLAGS_VECTORIZE
743743
CFLAGS_UNROLL_LOOPS
744+
PERMIT_MISSING_VARIABLE_DECLARATIONS
744745
PERMIT_DECLARATION_AFTER_STATEMENT
745746
LLVM_BINPATH
746747
LLVM_CXXFLAGS
@@ -6022,6 +6023,54 @@ if test x"$pgac_cv_prog_CXX_cxxflags__Wformat_security" = x"yes"; then
60226023
fi
60236024

60246025

6026+
# gcc 14+, clang for a while
6027+
# (Supported in C++ by clang but not gcc. For consistency, omit in C++.)
6028+
save_CFLAGS=$CFLAGS
6029+
6030+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wmissing-variable-declarations, for CFLAGS" >&5
6031+
$as_echo_n "checking whether ${CC} supports -Wmissing-variable-declarations, for CFLAGS... " >&6; }
6032+
if ${pgac_cv_prog_CC_cflags__Wmissing_variable_declarations+:} false; then :
6033+
$as_echo_n "(cached) " >&6
6034+
else
6035+
pgac_save_CFLAGS=$CFLAGS
6036+
pgac_save_CC=$CC
6037+
CC=${CC}
6038+
CFLAGS="${CFLAGS} -Wmissing-variable-declarations"
6039+
ac_save_c_werror_flag=$ac_c_werror_flag
6040+
ac_c_werror_flag=yes
6041+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6042+
/* end confdefs.h. */
6043+
6044+
int
6045+
main ()
6046+
{
6047+
6048+
;
6049+
return 0;
6050+
}
6051+
_ACEOF
6052+
if ac_fn_c_try_compile "$LINENO"; then :
6053+
pgac_cv_prog_CC_cflags__Wmissing_variable_declarations=yes
6054+
else
6055+
pgac_cv_prog_CC_cflags__Wmissing_variable_declarations=no
6056+
fi
6057+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
6058+
ac_c_werror_flag=$ac_save_c_werror_flag
6059+
CFLAGS="$pgac_save_CFLAGS"
6060+
CC="$pgac_save_CC"
6061+
fi
6062+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" >&5
6063+
$as_echo "$pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" >&6; }
6064+
if test x"$pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" = x"yes"; then
6065+
CFLAGS="${CFLAGS} -Wmissing-variable-declarations"
6066+
fi
6067+
6068+
6069+
PERMIT_MISSING_VARIABLE_DECLARATIONS=
6070+
if test x"$save_CFLAGS" != x"$CFLAGS"; then
6071+
PERMIT_MISSING_VARIABLE_DECLARATIONS=-Wno-missing-variable-declarations
6072+
fi
6073+
60256074
# Disable strict-aliasing rules; needed for gcc 3.3+
60266075

60276076
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -fno-strict-aliasing, for CFLAGS" >&5

‎configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,15 @@ if test "$GCC" = yes -a "$ICC" = no; then
518518
# This was included in -Wall/-Wformat in older GCC versions
519519
PGAC_PROG_CC_CFLAGS_OPT([-Wformat-security])
520520
PGAC_PROG_CXX_CFLAGS_OPT([-Wformat-security])
521+
# gcc 14+, clang for a while
522+
# (Supported in C++ by clang but not gcc. For consistency, omit in C++.)
523+
save_CFLAGS=$CFLAGS
524+
PGAC_PROG_CC_CFLAGS_OPT([-Wmissing-variable-declarations])
525+
PERMIT_MISSING_VARIABLE_DECLARATIONS=
526+
if test x"$save_CFLAGS" != x"$CFLAGS"; then
527+
PERMIT_MISSING_VARIABLE_DECLARATIONS=-Wno-missing-variable-declarations
528+
fi
529+
AC_SUBST(PERMIT_MISSING_VARIABLE_DECLARATIONS)
521530
# Disable strict-aliasing rules; needed for gcc 3.3+
522531
PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
523532
PGAC_PROG_CXX_CFLAGS_OPT([-fno-strict-aliasing])

‎meson.build

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,16 @@ if cc.has_argument('-Wdeclaration-after-statement')
19861986
cflags_no_decl_after_statement+='-Wno-declaration-after-statement'
19871987
endif
19881988

1989+
# Some code is not clean for -Wmissing-variable-declarations, so we
1990+
# make the "no" option available. Also, while clang supports this
1991+
# option for C++, gcc does not, so for consistency, leave it off for
1992+
# C++.
1993+
cflags_no_missing_var_decls= []
1994+
if cc.has_argument('-Wmissing-variable-declarations')
1995+
cflags_warn+='-Wmissing-variable-declarations'
1996+
cflags_no_missing_var_decls+='-Wno-missing-variable-declarations'
1997+
endif
1998+
19891999

19902000
# The following tests want to suppress various unhelpful warnings by adding
19912001
# -Wno-foo switches. But gcc won't complain about unrecognized -Wno-foo

‎src/Makefile.global.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ CFLAGS_POPCNT = @CFLAGS_POPCNT@
266266
CFLAGS_CRC = @CFLAGS_CRC@
267267
CFLAGS_XSAVE = @CFLAGS_XSAVE@
268268
PERMIT_DECLARATION_AFTER_STATEMENT = @PERMIT_DECLARATION_AFTER_STATEMENT@
269+
PERMIT_MISSING_VARIABLE_DECLARATIONS = @PERMIT_MISSING_VARIABLE_DECLARATIONS@
269270
CXXFLAGS = @CXXFLAGS@
270271

271272
LLVM_CPPFLAGS = @LLVM_CPPFLAGS@

‎src/interfaces/ecpg/test/Makefile.regress

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
override CPPFLAGS := -I../../include -I$(top_srcdir)/src/interfaces/ecpg/include \
55
-I$(libpq_srcdir) $(CPPFLAGS)
6-
override CFLAGS += $(PTHREAD_CFLAGS)
6+
override CFLAGS += $(PTHREAD_CFLAGS) $(PERMIT_MISSING_VARIABLE_DECLARATIONS)
77

88
LDFLAGS_INTERNAL += -L../../ecpglib -lecpg -L../../pgtypeslib -lpgtypes $(libpq)
99

‎src/interfaces/ecpg/test/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ testprep_targets += pg_regress_ecpg
2727

2828
# create .c files and executables from .pgc files
2929
ecpg_test_exec_kw= {
30+
'c_args': cflags_no_missing_var_decls,
3031
'dependencies': [frontend_code, libpq],
3132
'include_directories': [ecpg_inc],
3233
'link_with': [ecpglib_so, ecpg_compat_so, ecpg_pgtypes_so],

‎src/makefiles/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ pgxs_kv = {
9898
'CXXFLAGS_SL_MODULE':''.join(cxxflags_mod),
9999
'PERMIT_DECLARATION_AFTER_STATEMENT':
100100
''.join(cflags_no_decl_after_statement),
101+
'PERMIT_MISSING_VARIABLE_DECLARATIONS':
102+
''.join(cflags_no_missing_var_decls),
101103

102104
'CFLAGS_CRC':''.join(cflags_crc),
103105
'CFLAGS_POPCNT':''.join(cflags_popcnt),

‎src/tools/pg_bsd_indent/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ OBJS = \
2525
parse.o\
2626
pr_comment.o
2727

28+
$(OBJS): CFLAGS +=$(PERMIT_MISSING_VARIABLE_DECLARATIONS)
29+
2830
all: pg_bsd_indent
2931

3032
pg_bsd_indent:$(OBJS) | submake-libpgport

‎src/tools/pg_bsd_indent/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ endif
1818

1919
pg_bsd_indent=executable('pg_bsd_indent',
2020
pg_bsd_indent_sources,
21+
c_args: cflags_no_missing_var_decls,
2122
dependencies: [frontend_code],
2223
include_directories:include_directories('.'),
2324
kwargs: default_bin_args+ {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp