https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121563
--- Comment #12 from Harald van Dijk <harald at gigawatt dot nl> ---
(In reply to Christopher Bazley from comment #11)
> It includes the following new argument against permitting
> duplicate forward declarations (which may or may not be persuasive to the
> reader).
That isn't persuasive to me, no.
> Declarations that are valid at file scope are invalid in function scope:
>
> int x, x; // valid
> void f()
> {
> int x, x; // invalid
> }
That is a bit misleading. Multiple declarations are valid in file scope and in
function scope, so long as they are not definitions. It's just that your
function scope example is a definition, whereas your file scope example is only
a declaration (also a tentative definition, but that is not itself a
definition). If we change it so that we have a non-definition and a definition
at file scope, and a non-definition and a definition at function scope, we get
a better comparison.
int x, x; // declaration, okay
int x = 1, x = 1; // multiple definition, error
void f() {
extern int x, x; // declaration, okay
int x, x; // multiple definition, error
}
> The main precedent for forward parameter declarations is tentative
> definitions at file scope,
Multiple non-defining declarations being valid is the general rule, tentative
definitions are not a special exception.
typedef int x, x; // okay
void f(), f(); // okay
> If the above declaration were allowed in function scope, it would be
> ambiguous because it could be interpreted either as one declaration
> shadowing another or as a redeclaration. Duplicate forward parameter
> declarations are similarly ambiguous.
They aren't. Because forward parameter declarations are never definitions,
there is no ambiguity.
The only reason forward parameter declarations are a special case is that we do
not know yet at the end of the declarator whether the containing parameter-list
is part of (to use your names) a parameter-declaration is part of a
parameter-forward-declaration-list or of a parameter-type-list, we have to
continue parsing until we reach the end of the parameter-declaration to make
that determination. That may be justifiable as you and Alejandro also wrote for
simplicity of implementation, but it should not be presented as anything more
than that, in my opinion.