This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52953] function parameter name redeclarations not detected
- From: "egallager at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 19 Aug 2017 18:32:22 +0000
- Subject: [Bug c++/52953] function parameter name redeclarations not detected
- Auto-submitted: auto-generated
- References: <bug-52953-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52953
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2017-08-19
CC| |egallager at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #3 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to meng from comment #0)
> source code demonstrating the problem.
> ------------------------------- BEGIN ----------------------------
> void f (int i) try
> {
> void i (); // 1
> }
> catch (...)
> {
> void i (); // 2
> }
>
> int main ()
> {
> return 0;
> }
> ------------------------------- END ----------------------------
>
> compiled with :
> $HOME/gcc/4.7.0/bin/c++ -std=c++0x -Wall -O3 tt.cc
>
> compiler output :
> nothing
>
> g++-4.7.0 accepts the code as it is, issuing no warnings and no errors. I
> think this is wrong. According to c++11 3.3.3/2
> "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."
>
> In the above example, i is the name of the parameter of function f. The name
> i, therefore, cannot be redeclared in the outermost block of the function
> definition (case 1) nor can it be redeclared in the outermost block of any
> associated handler (case 2). But my g++ accepts both cases while they should
> be rejected.
I can get some other warnings from this but not what you want:
$ /usr/local/bin/g++ -c -std=c++0x -Wall -O3 -Wextra -Wshadow -pedantic
-Wmissing-declarations -Wredundant-decls 52953.c
52953.c:1:6: warning: no previous declaration for ‘void f(int)’
[-Wmissing-declarations]
void f (int i) try
^
52953.c: In function ‘void f(int)’:
52953.c:1:13: warning: unused parameter ‘i’ [-Wunused-parameter]
void f (int i) try
^
$
(In reply to meng from comment #1)
> another example showing violation of c++11 3.3.3/4
> ---------------------------- BEGIN -------------------------------
> int main ()
> {
> if (int a = 1)
> {
> void a (); // 1
> }
> else
> {
> void a (); // 2
> }
>
> while (int a = 0)
> {
> void a (); // 3
> }
>
> for (int a = 0;;)
> {
> void a (); // 4
> break;
> }
> for (; int a = 0;)
> {
> void a (); // 5
> }
>
> return 0;
> }
> ---------------------------- END -------------------------------
>
> According to my understanding, all numbered cases are illegal based on c++11
> 3.3.3/4.g++-4.7.0 correctly caught case 3 and 5 as compiler errors, the rest
> are accepted.
Yup, 3 and 5 are still the only ones that error:
$ /usr/local/bin/g++ -c -std=c++0x -Wall -O3 -Wextra -Wshadow -pedantic
-Wmissing-declarations -Wredundant-decls 52953_2.c
52953_2.c: In function ‘int main()’:
52953_2.c:3:10: warning: unused variable ‘a’ [-Wunused-variable]
if (int a = 1)
^
52953_2.c:14:11: error: ‘void a()’ redeclared as different kind of symbol
void a (); // 3
^
52953_2.c:12:13: note: previous declaration ‘int a’
while (int a = 0)
^
52953_2.c:12:13: warning: unused variable ‘a’ [-Wunused-variable]
52953_2.c:17:11: warning: unused variable ‘a’ [-Wunused-variable]
for (int a = 0;;)
^
52953_2.c:24:11: error: ‘void a()’ redeclared as different kind of symbol
void a (); // 5
^
52953_2.c:22:13: note: previous declaration ‘int a’
for (; int a = 0;)
^
52953_2.c:22:13: warning: unused variable ‘a’ [-Wunused-variable]
$
So, confirmed.