Created attachment 49098 [details] -save-temps *.i output When I compile the attached code with gcc -Wshadow ./gcc-shadow-test.c it passes with no output/warnings. The warning about shadowing is displayed properly by g++, clang and clang++ and the first print() actually proves that gcc does see the "environ" variable from unistd.h but ignores it when resolving shadowing. gcc -v: Using built-in specs. COLLECT_GCC=/usr/bin/gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-10.2.0/work/gcc-10.2.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/10.2.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/10.2.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/10.2.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/10.2.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/include/g++-v10 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/10.2.0/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 10.2.0 p1' --disable-esp --enable-libstdcxx-time --with-build-config=bootstrap-lto --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libssp --disable-libada --disable-systemtap --enable-vtable-verify --with-zstd --enable-lto --without-isl --enable-default-pie --enable-default-ssp Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.2.0 (Gentoo 10.2.0 p1)
This happens because environ is declared in a system header. The C frontend warns when both declarations are not in a system header. The C++ frontend warns when the second declaration is not in a system header. Intuitively, the C++ frontend's behaviour makes more sense to me, but that is just my personal opinion. The C frontend's behaviour was changed intentionally, see <https://gcc.gnu.org/legacy-ml/gcc-patches/2011-08/msg02017.html>, but -Wshadow has since been enhanced so that it no longer warns about object declarations shadowing functions. If that later enhancement already covers all of the cases that that initial system headers patch was meant to suppress warnings for, perhaps the initial patch can be reverted now?
Other compiler's behavior does makes more sense, but yeah, personal opinion. In case the patch ends up not being reverted the docs at https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wshadow should probably be clarified about what kind of shadowing is silently ignored.