Defect Report #035

Submission Date: 10 Dec 92
Submittor: WG14
Source: X3J11/91-039 (Derek M. Jones)
Question 1
void f(a, b)
int a(enum b {x, y});
int b;
{
}
Now this example is perverse because a prototype declaration is used to declare the parameter of an old-style function declaration. But anyway ...
Is the declaration of the parameter a legal or a constraint error?
Now a(...) is a declarator.
Subclause 6.7.1 says on page 82, lines 7-8:

... each declaration in the declaration list shall have at least one declarator, and those declarators shall declare only identifiers from the identifier list.

The identifier list contains a and b.
The declarator for parameter a declares the identifiers a, b, x, and y.
b is in the identifier list, so that is okay. But x and y are not. Constraint error (methinks so)?
See subclause 6.1.2, page 19 for a definition of an identifier.
Response
There is no constraint violation. The scopes of b, x, and y end at the right-parenthesis at the end of the enum, so there is no violation. It is difficult to call the function f, but there is no constraint violation. The phrase ``each declarator declares one identifier'' in subclause 6.5.4 refers to a, not to b, x, or y.
As an example, in the conforming definition:
void f(a, b)
int a(enum b{x, y});
int b;
{
}
the scope of b (the enum tag), x, and y ends at the right-parenthesis at the end of the enum (prototype scope).
Question 2
Also consider:
void g(c)
enum m{q, r} c;
{
}
What is the scope of m, q, and r?
Subclause 6.1.2.1 says on page 20, lines 28-29 ``... appears outside of any block or list of parameters, the identifier has file scope, ...''
It says on page 20, lines 30-31 ``... appears inside a block or within the list of parameter declarations in a function definition, the identifier has block scope, ...''
Now the above three identifiers appear outside of any block or list of parameters but they are within the list of parameter declarations.
Who wins?
Response
The scope of m, q, and r ends at the close-brace (block scope). The operative wording is the more specific statement on page 20, lines 30-31 ``... appears inside a block or within the list of parameter declarations in a function definition, the identifier has block scope, ...''
As an example, in the code fragment:
void g(c)
enum m{q, r} c;
{
}
the scope of m, q, and r ends at the closing brace of the function definition (block scope).

Previous Defect Report < - > Next Defect Report