1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Add -Wshadow=compatible-local to the standard compilation flags

Since cd4e8caaa, we've been able to build the source tree with
-Wshadow=compatible-local without any warnings.  Lots of work was done by
Justin Pryzby and I (David) to get all our code to compile warning free
with that flag.  In that process, 2 bugs (16d69ec29 and af7d270dd) were
discovered and fixed.  Additionally, "git log --grep=shadow" shows that
there is no shortage of other bugs that have been fixed over the years
which were caused by variable shadowing.

In light of the above, it seems very much worthwhile to add at least
-Wshadow=compatible-local to our standard compilation flags.  We *may*
want to go further and take this to -Wshadow=local in the future, but
we're not ready for that today, so let's add -Wshadow=compatible-local now
to help make sure we don't introduce further local variable shadowing.

Author: Andres Freund
Discussion: https://postgr.es/m/20221006003920.6xlqaoccxwisza5k@awork3.anarazel.de
This commit is contained in:
David Rowley
2022-10-07 16:50:31 +13:00
parent 80ef926758
commit 0fe954c285
3 changed files with 94 additions and 0 deletions

View File

@ -508,6 +508,8 @@ if test "$GCC" = yes -a "$ICC" = no; then
PGAC_PROG_CXX_CFLAGS_OPT([-Wimplicit-fallthrough=3])
PGAC_PROG_CC_CFLAGS_OPT([-Wcast-function-type])
PGAC_PROG_CXX_CFLAGS_OPT([-Wcast-function-type])
PGAC_PROG_CC_CFLAGS_OPT([-Wshadow=compatible-local])
PGAC_PROG_CXX_CFLAGS_OPT([-Wshadow=compatible-local])
# This was included in -Wall/-Wformat in older GCC versions
PGAC_PROG_CC_CFLAGS_OPT([-Wformat-security])
PGAC_PROG_CXX_CFLAGS_OPT([-Wformat-security])