[dcl.array] p8 A contradictory example and the rule should be improved
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
Description
[dcl.array] p8 says
Furthermore, if there is a reachable declaration of the entity that inhabits the same scope in which the bound was specified, an omitted array bound is taken to be the same as in that earlier declaration, and similarly for the definition of a static data member of a class.
Consider the example
struct S {
static int y[10];
};
int S::y[]; // OK, bound is 10
It's not true. Since the declaration outside the class definition does not inhabit the same scope as the initial declaration does. Since [basic.scope.scope] p2 says
Unless otherwise specified:
- [...]
- A declaration inhabits the immediate scope at its locus ([basic.scope.pdecl]).
The locus of the second declaration is immediately after the complete declarator, the scope it inhabits is the namespace scope. Moreover, [dcl.meaning.general] p3.1 strongly implies this point
If the id-expression in the declarator-id of the declarator is a qualified-id Q, let S be its lookup context ([basic.lookup.qual]); the declaration shall inhabit a namespace scope.
The comment is just wrong. If the comments are the intent. We might say
Furthermore, if there is a reachable declaration
Dto which the name is bound in the same scope in which the name introduced by another declarationD0that omits the array bound is bound, whereDandD0declares the same entity andDspecifies the array bound, the omitted array bound is taken to be the same asD.
extern int x[10];
void f() {
extern int x[]; // the name is bound in this scope rather than global namespace
int i = sizeof(x); // error: incomplete object type
}
The earlier declaration implies that the declaration with the specified bound should be declared before another declaration that omits the bound, which rejects this valid example
extern int arr[];
int arr[10];
int i = sizeof(arr);
@jensmaurer @opensdh
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read [dcl.array] p8 alongside [basic.scope.scope] p2 and [dcl.meaning.general] p3.1, then compare the two array-declaration examples in the issue. Done means the wording no longer contradicts the static data member example and still permits a bound to be specified after an omitted bound.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100