Bug 13717 - duplicated parameter name not caught ?
Summary: duplicated parameter name not caught ?
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.2
: P3 minor
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
: 17786 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-01-17 11:27 UTC by d.binderman
Modified: 2008-01-23 00:00 UTC (History)
4 users (show)

See Also:
Host: linux-i386
Target:
Build:
Known to work:
Known to fail: 3.3.2 3.4.0 4.0.0 2.95.3 3.0.4
Last reconfirmed: 2005-12-25 03:09:53


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description d.binderman 2004-01-17 11:28:00 UTC
The one liner

void f( int fred, char * fred);

is IMHO illegal code because fred is the name of two parameters.

I couldn't get gcc332 to find the bug in this code.
This is salted down from real code in Fedora Core 1.
Comment 1 Dara Hazeghi 2004-01-18 09:20:18 UTC
Confirmed with mainline/3.4 branch. C frontend properly rejects this, so this is
not a duplicate of PR13728.
Comment 2 Andrew Pinski 2004-10-03 19:52:52 UTC
*** Bug 17786 has been marked as a duplicate of this bug. ***
Comment 3 Wolfgang Bangerth 2004-10-04 12:45:07 UTC
As mentioned in PR 17786 by Nathan: 
 
correct. there is a related bug in that we fail to compile things like 
 
void foo (int x, int ary[sizeof(x)]); 
Comment 4 David Binderman 2006-03-15 10:42:57 UTC
(In reply to comment #0)
> The one liner
> 
> void f( int fred, char * fred);
> 
> is IMHO illegal code because fred is the name of two parameters.

I just checked gcc 4.2 and it is broken there as well.

Even adding flags -Wall -ansi -pedantic doesn't help
Comment 5 Richard Biener 2006-05-29 15:13:28 UTC
Based on 8.3.5/8 and the example from 8.3.6/9 which reads

 int f(int a, int b = a);

I think this bug is invalid and function declarations with duplicate parameter
names are not invalid.
Comment 6 Dirk Mueller 2006-05-29 16:26:26 UTC
it might not be invalid, but its certainly worth a diagnostic IMHO
Comment 7 David Binderman 2006-05-29 22:34:08 UTC
(In reply to comment #5)
> Based on 8.3.5/8 and the example from 8.3.6/9 which reads
> 
>  int f(int a, int b = a);
> 
> I think this bug is invalid and function declarations with duplicate parameter
> names are not invalid.

I don't understand how the line of code you mention helps
demonstrate your logic. Two parameters are declared, one
called a and one called b. 

In the standard, the end of paragraph 8.3.5.7 says

If a parameter name is present  in  a  function
  declaration that is not a definition, it cannot be used outside of the
  parameter-declaration-clause since it goes out of scope at the end  of
  the function declarator

So it implies that a new scope is entered at the (
and exited at the ). But we already know that a name can't 
be reused at the same scope [ except for function overloading,
but that's different]. QED.

Comment 8 Dmitry Tsarkov 2008-01-16 17:39:53 UTC
This is fixed in current mainline GCC (as per http://gcc.gnu.org/gcc-4.3/porting_to.html).
Comment 9 Wolfgang Bangerth 2008-01-22 22:06:20 UTC
Apparently fixed.