https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89616
Bug ID: 89616 Summary: Parameter names can be redeclared in outermost block of a function definition Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jtcash at ucsd dot edu Target Milestone: --- Created attachment 45913 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45913&action=edit The simplest .cpp file to experience this bug Affected Version: All versions I've tested on multiple platforms, spanning 4.1.2 to trunk. System Type: All platforms I've tested, including Window and Linux. Compiler Explorer shows it exists on all versions of GCC on all architectures. GCC Build Options: Any (details of one of the systems I tested on are provided below) Command to experience the bug: $ g++ -x c++ - -c <<< 'void f(int x){ void x(); }' Or just compile the attached example file however you want, such as: $ g++ -c gcc_redeclaration_bug.cpp -Wall -Wextra Expected Behavior: The compiler should fail and give an error message, as this code is invalid C++ code according to the standard. Actual Behavior: The code compiles fine, providing an unused parameter warning if -Wunused-parameter is enabled. The C++ standard states "A parameter name shall not be redeclared in the outermost block of the function definition nor in the outermost block of any handler associated with a function-try-block." Additional information/examples: Clang and MSVC both follow the standard correctly, and this bug is not present. Here is a Compiler Explorer link which demonstrates this bug: https://godbolt.org/z/X0ka5R Here is an Ideone link which demonstrates this bug: https://ideone.com/fwN7nO Here is the stackoverflow post where this bug was discovered: https://stackoverflow.com/q/55033461/ Exact version of GCC: I'll just provide info from one of the platforms I tested on, as it is in the bug report requirements. $ gcc -v Using built-in specs. COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../gcc-8.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=ada,c,lto,c++,objc,obj-c++,fortran --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev1, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld Thread model: posix gcc version 8.2.0 (Rev1, Built by MSYS2 project)